forked from KNEMC/KLALB
整理SRv6Router代码,修bug,增加SRHInsert虚链路
This commit is contained in:
@@ -63,6 +63,8 @@ public abstract class AbstractIPv6NetworkLink implements IPv6NetworkLink {
|
||||
}
|
||||
|
||||
private BiConsumer<IPv6NetworkLink, Supplier<IPv6Packet>> receiveConsumer;
|
||||
|
||||
private Supplier<Long> costSupplier;
|
||||
@Override
|
||||
public void setReceiveConsumer(BiConsumer<IPv6NetworkLink,Supplier< IPv6Packet>> receiveConsumer) {
|
||||
this.receiveConsumer = receiveConsumer;
|
||||
@@ -73,6 +75,14 @@ public abstract class AbstractIPv6NetworkLink implements IPv6NetworkLink {
|
||||
return loopback;
|
||||
}
|
||||
|
||||
public Supplier<Long> getCostSupplier() {
|
||||
return costSupplier;
|
||||
}
|
||||
|
||||
public void setCostSupplier(Supplier<Long> costSupplier) {
|
||||
this.costSupplier = costSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RouteItem> getRouteItems() {
|
||||
List<RouteItem> rlist = new ArrayList<>();
|
||||
@@ -86,12 +96,12 @@ public abstract class AbstractIPv6NetworkLink implements IPv6NetworkLink {
|
||||
for (Iterator<Neighbor> iteratorx = getNeighborsInfo().iterator(); iteratorx.hasNext();) {
|
||||
Neighbor addresses = (Neighbor) iteratorx.next();
|
||||
RouteItem ri = new RouteItem(new IPv6AddressGroup(addresses.getAddress().getAddress(), 128),
|
||||
addresses.getAddress().getAddress(), this,RouteItem.SRv6_ENDXSID, 0, 128, null, "D");
|
||||
addresses.getAddress().getAddress(), this,RouteItem.SRv6_ENDXSID, 0, 128, costSupplier, "D");
|
||||
rlist.add(ri);
|
||||
|
||||
RouteItem ris = new RouteItem(addresses.getLocator(),
|
||||
addresses.getLocator().getAddress(), this, RouteItem.SRv6_ENDSID, 13, 128,
|
||||
null, "D");
|
||||
costSupplier, "D");
|
||||
rlist.add(ris);
|
||||
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ public final class IPv6Address implements Comparable<IPv6Address> {
|
||||
((long)(bytes[15] & 0xFF));
|
||||
}
|
||||
|
||||
public IPv6Address(String string) throws UnknownHostException {
|
||||
this((Inet6Address) Inet6Address.getByName(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从两个long创建IPv6地址
|
||||
*/
|
||||
|
||||
@@ -67,7 +67,16 @@ public class IPv6AddressGroup implements Comparable<IPv6AddressGroup>{
|
||||
prefixLength=in.read();
|
||||
}
|
||||
public boolean checkMatch(IPv6Address address2) {
|
||||
return address2.equals(address.maskWith(IPv6Address.createMask(prefixLength)));
|
||||
IPv6Address cmsk= IPv6Address.createMask(prefixLength);
|
||||
return address2.maskWith(cmsk).equals(address.maskWith(cmsk));
|
||||
}
|
||||
/**
|
||||
* 返回裁剪后的路由表地址(主机位清零)。
|
||||
* 例如 2001:db8:1::100/64 → 2001:db8:1::/64
|
||||
*/
|
||||
public IPv6AddressGroup toNetworkRoute() {
|
||||
IPv6Address mask = IPv6Address.createMask(prefixLength);
|
||||
IPv6Address maskedAddr = address.maskWith(mask);
|
||||
return new IPv6AddressGroup(maskedAddr, prefixLength);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1378,7 +1378,7 @@ public class IPv6Packet extends NetworkPacket {
|
||||
// 重路由计数器
|
||||
private AtomicInteger rerouteCounter = new AtomicInteger(0);
|
||||
|
||||
public AtomicInteger getRerouteCounter() {
|
||||
public AtomicInteger getRouteCounter() {
|
||||
return rerouteCounter;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ public class RouteItem implements Comparable<RouteItem>,Cloneable{
|
||||
public static final String DIRECT="Direct";
|
||||
public static final String SRv6_ENDSID="SRv6 ENDSID";
|
||||
public static final String SRv6_ENDXSID="SRv6 ENDXSID";
|
||||
public static final String KLALB_SRv6 = "KLALB_SRv6";
|
||||
|
||||
private IPv6AddressGroup destination;
|
||||
private IPv6Address nexthop;
|
||||
@@ -39,7 +40,7 @@ public class RouteItem implements Comparable<RouteItem>,Cloneable{
|
||||
public RouteItem(IPv6AddressGroup destination, IPv6Address nexthop, IPv6NetworkLink destlink, String proto, int pre,
|
||||
long cost,String flag) {
|
||||
super();
|
||||
this.destination = destination;
|
||||
this.destination = destination.toNetworkRoute();
|
||||
this.nexthop = nexthop;
|
||||
this.destlink = destlink;
|
||||
this.proto = proto;
|
||||
@@ -50,7 +51,7 @@ public class RouteItem implements Comparable<RouteItem>,Cloneable{
|
||||
public RouteItem(IPv6AddressGroup destination, IPv6Address nexthop, IPv6NetworkLink destlink, String proto, int pre,
|
||||
long cost,Supplier<Long> costSupplier,String flag) {
|
||||
super();
|
||||
this.destination = destination;
|
||||
this.destination = destination.toNetworkRoute();
|
||||
this.nexthop = nexthop;
|
||||
this.destlink = destlink;
|
||||
this.proto = proto;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.kne.cloud.network.ipv6;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.kne.cloud.network.srv6.SRv6Router;
|
||||
|
||||
public class SRHInsertNetworkLink extends AbstractIPv6NetworkLink {
|
||||
|
||||
private IPv6AddressGroup ipgroup;
|
||||
|
||||
public SRHInsertNetworkLink(SRv6Router sRv6Router,IPv6AddressGroup ipgroup) {
|
||||
super(false);
|
||||
setSRv6Router(sRv6Router);
|
||||
this.ipgroup=ipgroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IPv6AddressGroup> getAddressGroups() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Neighbor> getNeighborsInfo() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(IPv6Packet pack, IPv6Address inet6Address) throws IOException {
|
||||
//getSrv6Router().insertHeaderAndRoutePacket(null, pack);
|
||||
System.out.println("insert:"+pack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RouteItem> getRouteItems() {
|
||||
return List.of(new RouteItem(ipgroup, null, this, RouteItem.KLALB_SRv6, 30, 0,"G"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SRHInsertNetworkLink";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user