forked from KNEMC/KLALB
KLALB V3.6.0 写了一半
This commit is contained in:
@@ -9,7 +9,7 @@ import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kne.cloud.network.klalb.IPSequence;
|
||||
import org.kne.cloud.network.ipv6.PacketID;
|
||||
|
||||
public class ACKSEQSSegmentRoutingTLV extends IPv6SegmentRoutingTLV {
|
||||
public ACKSEQSSegmentRoutingTLV(ByteBuffer klalbHeader) {
|
||||
@@ -21,17 +21,15 @@ public class ACKSEQSSegmentRoutingTLV extends IPv6SegmentRoutingTLV {
|
||||
return "ACKSEQSSegmentRoutingTLV [getSequence()=" + getSequence() + "]";
|
||||
}
|
||||
|
||||
public ACKSEQSSegmentRoutingTLV(UUID ackid, boolean promise) {
|
||||
public ACKSEQSSegmentRoutingTLV(UUID ackid,long sequence) {
|
||||
super(IPv6SegmentRoutingTLV.ACKSEQS);
|
||||
setUUID(ackid);
|
||||
setPromise(promise);
|
||||
getData().limit(22);
|
||||
getData().limit(30);
|
||||
}
|
||||
public ACKSEQSSegmentRoutingTLV(IPSequence ackid, boolean promise) {
|
||||
public ACKSEQSSegmentRoutingTLV(PacketID ackid) {
|
||||
super(IPv6SegmentRoutingTLV.ACKSEQS);
|
||||
setIPSequence(ackid);
|
||||
setPromise(promise);
|
||||
getData().limit(22);
|
||||
setPacketID(ackid);
|
||||
getData().limit(30);
|
||||
}
|
||||
public void setUUID(UUID uuid) {
|
||||
getData().putLong(6,uuid.getMostSignificantBits());
|
||||
@@ -41,12 +39,13 @@ public class ACKSEQSSegmentRoutingTLV extends IPv6SegmentRoutingTLV {
|
||||
public UUID getUUID() {
|
||||
return new UUID(getData().getLong(6),getData().getLong(14));
|
||||
}
|
||||
public void setIPSequence(IPSequence ackid) {
|
||||
setUUID(ackid.getUuid());
|
||||
public void setPacketID(PacketID ackid) {
|
||||
setUUID(ackid.getFlowuuid());
|
||||
setSequence(ackid.getSequence());
|
||||
}
|
||||
|
||||
public IPSequence getIPSequence() {
|
||||
return new IPSequence(getUUID(),isPromise());
|
||||
public PacketID getPacketID() {
|
||||
return new PacketID(getUUID(),getSequence());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,10 +62,10 @@ public class ACKSEQSSegmentRoutingTLV extends IPv6SegmentRoutingTLV {
|
||||
}
|
||||
|
||||
public long getSequence() {
|
||||
return getData().getLong(6);
|
||||
return getData().getLong(22);
|
||||
}
|
||||
public void setSequence(long sequence) {
|
||||
getData().putLong(6,sequence);
|
||||
getData().putLong(22,sequence);
|
||||
}
|
||||
public int getFlowNumber() {
|
||||
return getData().getInt(2);
|
||||
@@ -74,28 +73,6 @@ public class ACKSEQSSegmentRoutingTLV extends IPv6SegmentRoutingTLV {
|
||||
public void setFlowNumber(int flowsequence) {
|
||||
getData().putInt(2,flowsequence);
|
||||
}
|
||||
public void setACKIP(Inet6Address ip) {
|
||||
getData().put(14, ip.getAddress());
|
||||
}
|
||||
public Inet6Address getACKIP() {
|
||||
byte[]arr=new byte[16];
|
||||
getData().get(14,arr);
|
||||
try {
|
||||
return (Inet6Address) Inet6Address.getByAddress(arr);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public boolean isPromise() {
|
||||
return getData().get(0)!=0?true:false;
|
||||
}
|
||||
|
||||
|
||||
public void setPromise(boolean promise) {
|
||||
if(promise) {
|
||||
getData().put(0, (byte) 1);
|
||||
}else {
|
||||
getData().put(0, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package org.kne.cloud.network.srv6;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
public class DetNetSRv6TLV extends IPv6SegmentRoutingTLV {
|
||||
|
||||
// 标志位掩码定义
|
||||
public static final int FLAG_GUARANTEED_DELIVERY = 0x01; // 第1位: 承诺送达
|
||||
public static final int FLAG_AVOID_REORDERING = 0x02; // 第2位: 避免乱序
|
||||
public static final int FLAG_RESOURCE_RESERVED = 0x04; // 第3位: 资源预留
|
||||
public static final int FLAG_EXPLICIT_ROUTE = 0x08; // 第4位: 显式路由
|
||||
|
||||
// 保留其他位用于未来扩展 (0x10, 0x20, 0x40, 0x80)
|
||||
|
||||
public DetNetSRv6TLV(ByteBuffer buffer) {
|
||||
super(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public DetNetSRv6TLV(boolean guaranteedDelivery, boolean avoidReordering,
|
||||
boolean resourceReserved, boolean explicitRoute) {
|
||||
super(IPv6SegmentRoutingTLV.DETNET); // 使用建议的TLV类型编号
|
||||
|
||||
int flags = 0;
|
||||
if (guaranteedDelivery) flags |= FLAG_GUARANTEED_DELIVERY;
|
||||
if (avoidReordering) flags |= FLAG_AVOID_REORDERING;
|
||||
if (resourceReserved) flags |= FLAG_RESOURCE_RESERVED;
|
||||
if (explicitRoute) flags |= FLAG_EXPLICIT_ROUTE;
|
||||
|
||||
setFlags(flags);
|
||||
|
||||
// DetNet TLV数据部分:1字节标志位 + 5字节保留
|
||||
getData().put(1, (byte) 0); // 保留
|
||||
getData().put(2, (byte) 0); // 保留
|
||||
getData().put(3, (byte) 0); // 保留
|
||||
getData().put(4, (byte) 0); // 保留
|
||||
getData().put(5, (byte) 0); // 保留
|
||||
|
||||
getData().limit(6); // 总数据长度4字节
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return getData().get(0) & 0xff;
|
||||
}
|
||||
|
||||
public void setFlags(int flags) {
|
||||
getData().put(0, (byte) flags);
|
||||
}
|
||||
// 标志位getter/setter方法
|
||||
public boolean isGuaranteedDelivery() {
|
||||
return (getData().get(0) & FLAG_GUARANTEED_DELIVERY) != 0;
|
||||
}
|
||||
|
||||
public void setGuaranteedDelivery(boolean enabled) {
|
||||
byte flags = getData().get(0);
|
||||
if (enabled) {
|
||||
flags |= FLAG_GUARANTEED_DELIVERY;
|
||||
} else {
|
||||
flags &= ~FLAG_GUARANTEED_DELIVERY;
|
||||
}
|
||||
getData().put(0, flags);
|
||||
}
|
||||
|
||||
public boolean isAvoidReordering() {
|
||||
return (getData().get(0) & FLAG_AVOID_REORDERING) != 0;
|
||||
}
|
||||
|
||||
public void setAvoidReordering(boolean enabled) {
|
||||
byte flags = getData().get(0);
|
||||
if (enabled) {
|
||||
flags |= FLAG_AVOID_REORDERING;
|
||||
} else {
|
||||
flags &= ~FLAG_AVOID_REORDERING;
|
||||
}
|
||||
getData().put(0, flags);
|
||||
}
|
||||
|
||||
public boolean isResourceReserved() {
|
||||
return (getData().get(0) & FLAG_RESOURCE_RESERVED) != 0;
|
||||
}
|
||||
|
||||
public void setResourceReserved(boolean enabled) {
|
||||
byte flags = getData().get(0);
|
||||
if (enabled) {
|
||||
flags |= FLAG_RESOURCE_RESERVED;
|
||||
} else {
|
||||
flags &= ~FLAG_RESOURCE_RESERVED;
|
||||
}
|
||||
getData().put(0, flags);
|
||||
}
|
||||
|
||||
public boolean isExplicitRoute() {
|
||||
return (getData().get(0) & FLAG_EXPLICIT_ROUTE) != 0;
|
||||
}
|
||||
|
||||
public void setExplicitRoute(boolean enabled) {
|
||||
byte flags = getData().get(0);
|
||||
if (enabled) {
|
||||
flags |= FLAG_EXPLICIT_ROUTE;
|
||||
} else {
|
||||
flags &= ~FLAG_EXPLICIT_ROUTE;
|
||||
}
|
||||
getData().put(0, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DetNetSRv6TLV [" +
|
||||
"guaranteedDelivery=" + isGuaranteedDelivery() +
|
||||
", avoidReordering=" + isAvoidReordering() +
|
||||
", resourceReserved=" + isResourceReserved() +
|
||||
", explicitRoute=" + isExplicitRoute() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
super.writeToChannel(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromChannel(ReadableByteChannel din, long length) throws IOException {
|
||||
super.readFromChannel(din, length);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ public class IPv6SegmentRoutingTLV extends TLV {
|
||||
public static final int PAD1=0;
|
||||
public static final int PADN=4;
|
||||
public static final int HMAC=5;
|
||||
public static final int DETNET=6;
|
||||
public static final int SEQS=7;
|
||||
public static final int ACKSEQS=8;
|
||||
|
||||
@@ -56,14 +57,14 @@ public class IPv6SegmentRoutingTLV extends TLV {
|
||||
rtlv=new PADNSegmentRoutingTLV(bbf);
|
||||
rtlv.readFromChannel(din);
|
||||
return rtlv;
|
||||
case SEQS:
|
||||
rtlv=new SEQSSegmentRoutingTLV(bbf);
|
||||
rtlv.readFromChannel(din);
|
||||
return rtlv;
|
||||
case ACKSEQS:
|
||||
rtlv=new ACKSEQSSegmentRoutingTLV(bbf);
|
||||
rtlv.readFromChannel(din);
|
||||
return rtlv;
|
||||
case DETNET:
|
||||
rtlv=new DetNetSRv6TLV(bbf);
|
||||
rtlv.readFromChannel(din);
|
||||
return rtlv;
|
||||
default:
|
||||
rtlv=new IPv6SegmentRoutingTLV(bbf);
|
||||
rtlv.readFromChannel(din);
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Set;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
@@ -33,8 +33,9 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.network.ByteBufferAllocator;
|
||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.Neighbor;
|
||||
import org.kne.cloud.network.klalb.KLALBVirtualRawSocket;
|
||||
import org.kne.cloud.network.monitor.DelayMonitorData;
|
||||
@@ -52,12 +53,12 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
private static final boolean debug = false;
|
||||
|
||||
private RouterInfo selfRouterInfo;
|
||||
private Map<Inet6Address, RouterInfo> netmap=new ConcurrentHashMap<>();
|
||||
private Map<IPv6Address, RouterInfo> netmap=new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private volatile Map<Inet6Address,Long>addresses;
|
||||
private volatile Map<IPv6Address,Long>addresses;
|
||||
|
||||
private volatile Map<Inet6Address, List<LinkDirection>> paths;
|
||||
private volatile Map<IPv6Address, List<LinkDirection>> paths;
|
||||
|
||||
|
||||
|
||||
@@ -105,7 +106,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
Thread.currentThread().setName("KLALB路由协议接收线程");
|
||||
getSelfRouterInfo();
|
||||
try{
|
||||
ds=new KLALBVirtualRawSocket(router.getinLoopback(),router.getLocator().getAddress(), DEFAULT_PROTOCOL_NUMBER);
|
||||
ds=new KLALBVirtualRawSocket(router.getinLoopback(),router.getLocator().getAddress().toInet6Address(), DEFAULT_PROTOCOL_NUMBER);
|
||||
new Thread(()->{
|
||||
Thread.currentThread().setName("KLALB路由协议发送线程");
|
||||
|
||||
@@ -138,7 +139,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
floodPacket( null, new RouterInfoPacket(selfRouterInfo,true,-1));
|
||||
}
|
||||
|
||||
if(cur-floodTimer2>1000000000L) {
|
||||
if(cur-floodTimer2>2000000000L) {
|
||||
if(debug)
|
||||
System.out.println("update1");
|
||||
floodTimer2=cur;
|
||||
@@ -146,8 +147,8 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
}
|
||||
|
||||
//Set<Inet6Address> requestSet=new HashSet<>();
|
||||
for (Iterator<Entry<Inet6Address, RouterInfo>> iterator = netmap.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, RouterInfo> type = (Entry<Inet6Address, RouterInfo>) iterator.next();
|
||||
for (Iterator<Entry<IPv6Address, RouterInfo>> iterator = netmap.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<IPv6Address, RouterInfo> type = (Entry<IPv6Address, RouterInfo>) iterator.next();
|
||||
RouterInfo val=type.getValue();
|
||||
long timeout=30000000000L;
|
||||
if(val.getAsn()==router.getASN()) {
|
||||
@@ -191,8 +192,8 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
|
||||
}*/
|
||||
|
||||
for (Iterator<Entry<Inet6Address, HotspotAddressTimer>> iterator = hotspots.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, HotspotAddressTimer> type = (Entry<Inet6Address, HotspotAddressTimer>) iterator.next();
|
||||
for (Iterator<Entry<IPv6Address, HotspotAddressTimer>> iterator = hotspots.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<IPv6Address, HotspotAddressTimer> type = (Entry<IPv6Address, HotspotAddressTimer>) iterator.next();
|
||||
//if(type.getValue().checkReportTime()) {
|
||||
//System.out.println("hotspot address:"+type.getKey());
|
||||
//writePacket(ds2, new RouterInfoPacket( netmap.get(router.getLocator().getAddress()),false,-1), new InetSocketAddress(type.getKey(), DEFAULT_PORT));
|
||||
@@ -203,7 +204,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
|
||||
}
|
||||
|
||||
Thread.sleep(1);
|
||||
Thread.sleep(20);
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
@@ -217,7 +218,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
while(true) {
|
||||
|
||||
try {
|
||||
byte[]ca=ByteBufferAllocator.allocateArray(65535);
|
||||
byte[]ca=ByteBufferAllocator.allocateUninitializedArray(65535);
|
||||
DatagramPacket dgp=new DatagramPacket(ca, ca.length);
|
||||
ds.receive(dgp);
|
||||
//System.out.println(Arrays.toString( Arrays.copyOf( dgp.getData(),dgp.getLength())));
|
||||
@@ -286,15 +287,19 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
private void floodPacket(SocketAddress except,RouterInfoPacket rifp) throws IOException {
|
||||
long asn=rifp.getASN();
|
||||
List<Neighbor>ln= router.getNeighbors();
|
||||
Set<InetSocketAddress>ist=new HashSet<InetSocketAddress>();
|
||||
for(Neighbor addresses :ln) {
|
||||
if(addresses.getLocator()==null)
|
||||
continue;
|
||||
InetSocketAddress isa=new InetSocketAddress(addresses.getLocator().getAddress(),DEFAULT_PORT);
|
||||
InetSocketAddress isa=new InetSocketAddress(addresses.getLocator().getAddress().toInet6Address(),DEFAULT_PORT);
|
||||
if(!ist.add(isa)) {
|
||||
continue;
|
||||
}
|
||||
if(!isa.equals(except)) {
|
||||
if(asn==-1) {
|
||||
writePacket( rifp, isa);
|
||||
}else{
|
||||
RouterInfo nif= netmap.get(isa.getAddress());
|
||||
RouterInfo nif= netmap.get( IPv6Address.valueOf( isa.getAddress()));
|
||||
if(nif!=null&&nif.getAsn()==asn) {
|
||||
writePacket( rifp, isa);
|
||||
}
|
||||
@@ -332,29 +337,41 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
|
||||
private static class NetmapDirections{
|
||||
|
||||
public NetmapDirections(long[] direction, List<Inet6Address> rias,
|
||||
Map<Inet6Address, Long> direction_airs) {
|
||||
public NetmapDirections(long[] direction, List<IPv6Address> rias,
|
||||
Map<IPv6Address, Long> direction_airs) {
|
||||
super();
|
||||
this.direction = direction;
|
||||
this.direction_rias = rias;
|
||||
this.direction_airs = direction_airs;
|
||||
}
|
||||
|
||||
public NetmapDirections(long[] direction, List<Inet6Address> rias, Map<Inet6Address, Long> airs,Object obj) {
|
||||
this.direction = direction;
|
||||
this.direction_rias=new ArrayList<IPv6Address>();
|
||||
rias.forEach((addr)->{
|
||||
direction_rias.add(new IPv6Address(addr));
|
||||
});
|
||||
this.direction_airs=new HashMap<>();
|
||||
airs.forEach((k,v)->{
|
||||
direction_airs.put(new IPv6Address(k), v);
|
||||
});
|
||||
}
|
||||
|
||||
private long[] direction;
|
||||
|
||||
private List<Inet6Address> direction_rias;
|
||||
private List<IPv6Address> direction_rias;
|
||||
|
||||
private Map<Inet6Address, Long> direction_airs;
|
||||
private Map<IPv6Address, Long> direction_airs;
|
||||
|
||||
public long[] getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public List<Inet6Address> getDirection_rias() {
|
||||
public List<IPv6Address> getDirection_rias() {
|
||||
return direction_rias;
|
||||
}
|
||||
|
||||
public Map<Inet6Address, Long> getDirection_airs() {
|
||||
public Map<IPv6Address, Long> getDirection_airs() {
|
||||
return direction_airs;
|
||||
}
|
||||
|
||||
@@ -380,14 +397,14 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
if(netmap.get(router.getLocator().getAddress())==null) {
|
||||
return;
|
||||
}
|
||||
Set<Entry<Inet6Address, RouterInfo>> s=netmap.entrySet();
|
||||
Map<Inet6Address,Long>airs=new HashMap<>(netmap.size()*2,0.4f);
|
||||
Set<Entry<IPv6Address, RouterInfo>> s=netmap.entrySet();
|
||||
Map<IPv6Address,Long>airs=new HashMap<>(netmap.size()*2,0.4f);
|
||||
|
||||
List<Inet6Address>rias=new ArrayList<>(netmap.size()+1);
|
||||
List<IPv6Address>rias=new ArrayList<>(netmap.size()+1);
|
||||
|
||||
Map<Inet6Address,List< LinkDirection>>paths=new HashMap<>();
|
||||
Map<IPv6Address,List< LinkDirection>>paths=new HashMap<>();
|
||||
long number=0;
|
||||
for(Entry<Inet6Address, RouterInfo> entry:s) {
|
||||
for(Entry<IPv6Address, RouterInfo> entry:s) {
|
||||
if(!airs.containsKey(entry.getKey())) {
|
||||
airs.put(entry.getKey(),number);
|
||||
rias.add( entry.getKey());
|
||||
@@ -395,7 +412,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
}
|
||||
List<NeighborInfo> ni= entry.getValue().getNeighborAddresses();
|
||||
for(NeighborInfo neighborInfo :ni) {
|
||||
Inet6Address ias2=neighborInfo.getLocator().getAddress();
|
||||
IPv6Address ias2=neighborInfo.getLocator().getAddress();
|
||||
if(!airs.containsKey(ias2)) {
|
||||
airs.put(ias2,number);
|
||||
rias.add( ias2);
|
||||
@@ -423,7 +440,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
long[][]pointers=new long[(int) airs.size()][2];
|
||||
long heappos=0;
|
||||
long linknumber=0;
|
||||
for(Entry<Inet6Address, List<LinkDirection>> entry:paths.entrySet()) {
|
||||
for(Entry<IPv6Address, List<LinkDirection>> entry:paths.entrySet()) {
|
||||
/*for (Iterator<Entry<Inet6Address, Set<LinkDirection>>> iterator = paths.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, Set<LinkDirection>> entry = (Entry<Inet6Address, Set<LinkDirection>>) iterator.next();*/
|
||||
linknumber+=entry.getValue().size();
|
||||
@@ -432,7 +449,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
for (long i = 0; i < number; i++) {
|
||||
long heapindex=0;
|
||||
pointers[(int) i][0]=heappos;
|
||||
InetAddress ia=rias.get((int) i);
|
||||
IPv6Address ia=rias.get((int) i);
|
||||
List<LinkDirection>lks=paths.get(ia);
|
||||
if(lks!=null)
|
||||
for(LinkDirection linkPath:lks) {
|
||||
@@ -464,10 +481,10 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
//System.out.println(Arrays.toString( algorithm.getDirection()));
|
||||
}
|
||||
public static class LinkDirection{
|
||||
private Inet6AddressGroup fromAddress;
|
||||
private Inet6AddressGroup toAddress;
|
||||
private Inet6Address fromLocator;
|
||||
private Inet6Address toLocator;
|
||||
private IPv6AddressGroup fromAddress;
|
||||
private IPv6AddressGroup toAddress;
|
||||
private IPv6Address fromLocator;
|
||||
private IPv6Address toLocator;
|
||||
private long delay;
|
||||
private long delayMin;
|
||||
private long speed;
|
||||
@@ -475,10 +492,10 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
return speed;
|
||||
}
|
||||
private long bandwidth;
|
||||
public Inet6AddressGroup getFromAddress() {
|
||||
public IPv6AddressGroup getFromAddress() {
|
||||
return fromAddress;
|
||||
}
|
||||
public Inet6AddressGroup getToAddress() {
|
||||
public IPv6AddressGroup getToAddress() {
|
||||
return toAddress;
|
||||
}
|
||||
public long getDelay() {
|
||||
@@ -492,8 +509,8 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
return delayMin;
|
||||
}
|
||||
|
||||
public LinkDirection(Inet6AddressGroup fromAddress, Inet6AddressGroup toAddress, Inet6Address fromLocator,
|
||||
Inet6Address toLocator, long delay, long delayMin, long speed, long bandwidth) {
|
||||
public LinkDirection(IPv6AddressGroup fromAddress, IPv6AddressGroup toAddress, IPv6Address fromLocator,
|
||||
IPv6Address toLocator, long delay, long delayMin, long speed, long bandwidth) {
|
||||
super();
|
||||
this.fromAddress = fromAddress;
|
||||
this.toAddress = toAddress;
|
||||
@@ -510,7 +527,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
+ fromLocator + ", toLocator=" + toLocator + ", delay=" + delay + ", delayMin=" + delayMin
|
||||
+ ", speed=" + speed + ", bandwidth=" + bandwidth + "]";
|
||||
}
|
||||
public Inet6Address getFromLocator() {
|
||||
public IPv6Address getFromLocator() {
|
||||
return fromLocator;
|
||||
}
|
||||
@Override
|
||||
@@ -528,7 +545,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
LinkDirection other = (LinkDirection) obj;
|
||||
return Objects.equals(fromAddress, other.fromAddress) && Objects.equals(toAddress, other.toAddress);
|
||||
}
|
||||
public Inet6Address getToLocator() {
|
||||
public IPv6Address getToLocator() {
|
||||
return toLocator;
|
||||
}
|
||||
public long getWeight() {
|
||||
@@ -569,8 +586,8 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
downloadspeed=((SpeedAndTrafficMonitorData) md).getInSpeed();
|
||||
if(md instanceof SpeedAndTrafficMonitorDataImpl) {
|
||||
SpeedAndTrafficMonitorDataImpl smd=(SpeedAndTrafficMonitorDataImpl) md;
|
||||
uploadspeedmax=smd.getOutSpeedMax2();
|
||||
downloadspeedmax=smd.getInSpeedMax2();
|
||||
uploadspeedmax=smd.getOutSpeedMax();
|
||||
downloadspeedmax=smd.getInSpeedMax();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -586,13 +603,13 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
return ri;
|
||||
}
|
||||
|
||||
public Map<Inet6Address, Long> getAddresses() {
|
||||
public Map<IPv6Address, Long> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
public Map<Inet6Address, List<LinkDirection>> getPaths() {
|
||||
public Map<IPv6Address, List<LinkDirection>> getPaths() {
|
||||
return paths;
|
||||
}
|
||||
public List<Inet6Address> createSegmentList(Inet6Address dest) {
|
||||
public List<IPv6Address> createSegmentList(IPv6Address dest) {
|
||||
NetmapDirections directionsx=directions;
|
||||
if(directionsx==null) {
|
||||
return null;
|
||||
@@ -601,7 +618,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
if(dn==null) {
|
||||
return null;
|
||||
}
|
||||
List<Inet6Address>segments=new ArrayList<>();
|
||||
List<IPv6Address>segments=new ArrayList<>();
|
||||
while(true) {
|
||||
long idx=directionsx.getDirection()[(int) dn.longValue()];
|
||||
if(idx==-1) {
|
||||
@@ -638,28 +655,28 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Inet6Address, HotspotAddressTimer> hotspots=new ConcurrentHashMap<>();
|
||||
public void putHotspotAddress(Inet6Address sourceAddress) {
|
||||
private Map<IPv6Address, HotspotAddressTimer> hotspots=new ConcurrentHashMap<>();
|
||||
public void putHotspotAddress(IPv6Address iPv6Address) {
|
||||
if(true) {
|
||||
HotspotAddressTimer hat=hotspots.get(sourceAddress);
|
||||
HotspotAddressTimer hat=hotspots.get(iPv6Address);
|
||||
if(hat==null) {
|
||||
hotspots.put(sourceAddress,hat= new HotspotAddressTimer());
|
||||
hotspots.put(iPv6Address,hat= new HotspotAddressTimer());
|
||||
}else {
|
||||
hat.refreshTimeout();
|
||||
}
|
||||
if(hat.checkReportTime()) {
|
||||
//System.out.println("hotspot address:"+sourceAddress);
|
||||
try {
|
||||
writePacket( new RouterInfoPacket( netmap.get(router.getLocator().getAddress()),false,-1), new InetSocketAddress(sourceAddress, DEFAULT_PORT));
|
||||
/* try {
|
||||
writePacket( new RouterInfoPacket( netmap.get(router.getLocator().getAddress()),false,-1), new InetSocketAddress(iPv6Address.toInet6Address(), DEFAULT_PORT));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
private Map<Inet6Address,Long> toIpBandwidth=new ConcurrentHashMap<Inet6Address,Long>();
|
||||
private Map<IPv6Address,Long> toIpBandwidth=new ConcurrentHashMap<IPv6Address,Long>();
|
||||
|
||||
public void updateTotalRequestBandwidth(Inet6Address targetaAddress, Long treq) {
|
||||
public void updateTotalRequestBandwidth(IPv6Address targetaAddress, Long treq) {
|
||||
Objects.requireNonNull(targetaAddress);
|
||||
//System.out.println("到"+targetaAddress.getHostAddress()+"请求带宽更新:"+treq);
|
||||
if(treq<=0) {
|
||||
@@ -673,7 +690,7 @@ public class KLALBRoutingProtocol extends Thread{
|
||||
}
|
||||
}
|
||||
}
|
||||
public Inet6Address getDijkstraPrevNode(Inet6Address text) {
|
||||
public IPv6Address getDijkstraPrevNode(IPv6Address text) {
|
||||
NetmapDirections directionsx=directions;
|
||||
if(directionsx==null)
|
||||
return null;
|
||||
|
||||
@@ -12,15 +12,15 @@ import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.congress.ECNCongressAlgorithm;
|
||||
import org.kne.cloud.network.congress.EmptyCongressAlgorithm;
|
||||
import org.kne.cloud.network.congress.SendPacketSlidingWindow;
|
||||
import org.kne.cloud.network.congestion.DCTCPCongestionAlgorithm;
|
||||
import org.kne.cloud.network.congestion.EmptyCongestionAlgorithm;
|
||||
import org.kne.cloud.network.congestion.SendPacketSlidingWindow;
|
||||
import org.kne.opencl64.Releaser;
|
||||
|
||||
public class KLALBRoutingProtocolAPIClient {
|
||||
private KLALBRoutingProtocol routingProtocol;
|
||||
private SendPacketSlidingWindow<UUID, JsonDataPacket> window = new SendPacketSlidingWindow<UUID, JsonDataPacket>(
|
||||
new EmptyCongressAlgorithm(3000000000L), 1024 * 1024);
|
||||
new EmptyCongestionAlgorithm(3000000000L), 1024 * 1024);
|
||||
|
||||
private static final Cleaner clr = Cleaner.create();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.function.BiConsumer;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.congress.SendPacketSlidingWindow;
|
||||
import org.kne.cloud.network.congestion.SendPacketSlidingWindow;
|
||||
import org.kne.cloud.network.klalb.KLALBController;
|
||||
import org.kne.opencl64.Releaser;
|
||||
|
||||
@@ -27,8 +27,10 @@ public class KLALBRoutingProtocolAPIServer {
|
||||
InetSocketAddress addrs=(InetSocketAddress) addr;
|
||||
switch(dataobj.getType()){
|
||||
case KLALBRoutingProtocolJsonData.OPEN_LINES_REQ:
|
||||
if(controller.getConfigItem()==null||(!controller.getConfigItem().isDenyLineTableQuery())) {
|
||||
KLALBRoutingProtocolJsonData json=new KLALBRoutingProtocolJsonData(KLALBRoutingProtocolJsonData.OPEN_LINES_RESP,dataobj.getUuid(),controller.getSelflineTable());
|
||||
routingProtocol.sendJsonPacketToAddress(new JsonDataPacket(json),addr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.io.Serializable;
|
||||
import java.net.Inet6Address;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.Neighbor;
|
||||
|
||||
public class NeighborInfo implements Serializable {
|
||||
@@ -24,11 +24,11 @@ public class NeighborInfo implements Serializable {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Inet6AddressGroup local;
|
||||
private Inet6AddressGroup neighbor;
|
||||
private Inet6AddressGroup locator;
|
||||
private IPv6AddressGroup local;
|
||||
private IPv6AddressGroup neighbor;
|
||||
private IPv6AddressGroup locator;
|
||||
private transient Neighbor context;
|
||||
public NeighborInfo(Inet6AddressGroup local,Inet6AddressGroup neighbor,Inet6AddressGroup locator, long uploadDelay, long downloadDelay,long uploadDelayMin, long downloadDelayMin, long uploadSpeed, long downloadSpeed, long uploadspeedmax, long downloadspeedmax) {
|
||||
public NeighborInfo(IPv6AddressGroup local,IPv6AddressGroup neighbor,IPv6AddressGroup locator, long uploadDelay, long downloadDelay,long uploadDelayMin, long downloadDelayMin, long uploadSpeed, long downloadSpeed, long uploadspeedmax, long downloadspeedmax) {
|
||||
super();
|
||||
this.local=local;
|
||||
this.neighbor = neighbor;
|
||||
@@ -62,10 +62,10 @@ public class NeighborInfo implements Serializable {
|
||||
public Neighbor getContext() {
|
||||
return context;
|
||||
}
|
||||
public Inet6AddressGroup getNeighbor() {
|
||||
public IPv6AddressGroup getNeighbor() {
|
||||
return neighbor;
|
||||
}
|
||||
public void setNeighbor(Inet6AddressGroup neighbor) {
|
||||
public void setNeighbor(IPv6AddressGroup neighbor) {
|
||||
this.neighbor = neighbor;
|
||||
}
|
||||
public long getUploadDelay() {
|
||||
@@ -104,16 +104,16 @@ public class NeighborInfo implements Serializable {
|
||||
public void setDownloadSpeed(long downloadSpeed) {
|
||||
this.downloadSpeed = downloadSpeed;
|
||||
}
|
||||
public Inet6AddressGroup getLocal() {
|
||||
public IPv6AddressGroup getLocal() {
|
||||
return local;
|
||||
}
|
||||
public void setLocal(Inet6AddressGroup local) {
|
||||
public void setLocal(IPv6AddressGroup local) {
|
||||
this.local = local;
|
||||
}
|
||||
public Inet6AddressGroup getLocator() {
|
||||
public IPv6AddressGroup getLocator() {
|
||||
return locator;
|
||||
}
|
||||
public void setLocator(Inet6AddressGroup locator) {
|
||||
public void setLocator(IPv6AddressGroup locator) {
|
||||
this.locator = locator;
|
||||
}
|
||||
|
||||
@@ -148,9 +148,9 @@ public class NeighborInfo implements Serializable {
|
||||
}
|
||||
|
||||
public void readFromStream(DataInputStream in) throws IOException {
|
||||
local=new Inet6AddressGroup(in);
|
||||
neighbor=new Inet6AddressGroup( in);
|
||||
locator=new Inet6AddressGroup(in);
|
||||
local=new IPv6AddressGroup(in);
|
||||
neighbor=new IPv6AddressGroup( in);
|
||||
locator=new IPv6AddressGroup(in);
|
||||
uploadDelay=in.readLong();
|
||||
downloadDelay=in.readLong();
|
||||
uploadDelayMin=in.readLong();
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
|
||||
public class RouterInfo implements Serializable{
|
||||
|
||||
@@ -29,12 +29,12 @@ public class RouterInfo implements Serializable{
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Inet6AddressGroup locator;
|
||||
private IPv6AddressGroup locator;
|
||||
private long asn;
|
||||
public Inet6AddressGroup getLocator() {
|
||||
public IPv6AddressGroup getLocator() {
|
||||
return locator;
|
||||
}
|
||||
public void setLocator(Inet6AddressGroup locator) {
|
||||
public void setLocator(IPv6AddressGroup locator) {
|
||||
this.locator = locator;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class RouterInfo implements Serializable{
|
||||
return neighborAddresses;
|
||||
}
|
||||
|
||||
public RouterInfo( long createTime,Inet6AddressGroup locator,long asn) {
|
||||
public RouterInfo( long createTime,IPv6AddressGroup locator,long asn) {
|
||||
this.createTime = createTime;
|
||||
this.locator=locator;
|
||||
this.asn=asn;
|
||||
@@ -115,7 +115,7 @@ public class RouterInfo implements Serializable{
|
||||
readFromStream(new DataInputStream(Channels.newInputStream(din)));
|
||||
}
|
||||
public void readFromStream(DataInputStream in) throws IOException {
|
||||
locator=new Inet6AddressGroup(in);
|
||||
locator=new IPv6AddressGroup(in);
|
||||
asn=in.readLong();
|
||||
createTime=in.readLong();
|
||||
int size=in.readInt();
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
|
||||
public class RouterInfoPacket extends KLALBRoutingProtocolPacket implements Serializable{
|
||||
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package org.kne.cloud.network.srv6;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SEQSSegmentRoutingTLV extends IPv6SegmentRoutingTLV {
|
||||
public SEQSSegmentRoutingTLV(ByteBuffer klalbHeader) {
|
||||
super(klalbHeader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SEQSSegmentRoutingTLV [getSequence()=" + getSequence() + "]";
|
||||
}
|
||||
|
||||
public SEQSSegmentRoutingTLV(long sequence,UUID uuid, boolean promise,boolean keeporder/*,int flownumber,long flowsequence*/) {
|
||||
super(IPv6SegmentRoutingTLV.SEQS);
|
||||
setSequence(sequence);
|
||||
setUUID(uuid);
|
||||
setPromise(promise);
|
||||
setKeepOrder(keeporder);
|
||||
//setFlowNumber(flownumber);
|
||||
//setFlowSequence(flowsequence);
|
||||
//getData().limit(14);
|
||||
//getData().limit(22);
|
||||
getData().limit(30);
|
||||
}
|
||||
|
||||
public void setUUID(UUID uuid) {
|
||||
getData().putLong(14,uuid.getMostSignificantBits());
|
||||
getData().putLong(22,uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return new UUID(getData().getLong(14),getData().getLong(22));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
|
||||
super.writeToChannel(dto);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromChannel(ReadableByteChannel din, long length) throws IOException {
|
||||
super.readFromChannel(din, length);
|
||||
|
||||
}
|
||||
|
||||
public long getSequence() {
|
||||
return getData().getLong(6);
|
||||
}
|
||||
public void setSequence(long sequence) {
|
||||
getData().putLong(6,sequence);
|
||||
}
|
||||
|
||||
public int getFlowNumber() {
|
||||
return getData().getInt(2);
|
||||
}
|
||||
public void setFlowNumber(int flowsequence) {
|
||||
getData().putInt(2,flowsequence);
|
||||
}
|
||||
|
||||
/*public long getFlowSequence() {
|
||||
return getData().getLong(14);
|
||||
}
|
||||
public void setFlowSequence(long flowsequence) {
|
||||
getData().putLong(14,flowsequence);
|
||||
}*/
|
||||
|
||||
public boolean isPromise() {
|
||||
return getData().get(0)!=0?true:false;
|
||||
}
|
||||
|
||||
public void setPromise(boolean promise) {
|
||||
if(promise) {
|
||||
getData().put(0, (byte) 1);
|
||||
}else {
|
||||
getData().put(0, (byte) 0);
|
||||
}
|
||||
}
|
||||
public boolean isKeepOrder() {
|
||||
return getData().get(1)!=0?true:false;
|
||||
}
|
||||
|
||||
public void setKeepOrder(boolean keeporder) {
|
||||
if(keeporder) {
|
||||
getData().put(1, (byte) 1);
|
||||
}else {
|
||||
getData().put(1, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class SRv6PacketReorder {
|
||||
while(true) {
|
||||
PacketTimeEntry i6p=map.remove(seqptr.get());
|
||||
if(i6p!=null) {
|
||||
//System.out.println("Ord:"+i6p.getFlowLabel()+" "+seqptr.get());
|
||||
System.out.println("Ord:"+i6p.packet.getFlowLabel()+" "+seqptr.get());
|
||||
seqptr.getAndIncrement();
|
||||
orderTime=System.nanoTime();
|
||||
if(packetConsumer!=null&&(!i6p.accepted)) {
|
||||
@@ -65,7 +65,7 @@ public class SRv6PacketReorder {
|
||||
packetConsumer.accept(i6p.packet);
|
||||
}
|
||||
}else {
|
||||
for(int i=1;i<5;i++) {
|
||||
/*for(int i=1;i<3;i++) {
|
||||
PacketTimeEntry i6px=map.get(seqptr.get()+i);
|
||||
if(i6px!=null) {
|
||||
if(packetConsumer!=null&&(!i6px.accepted)) {
|
||||
@@ -73,7 +73,7 @@ public class SRv6PacketReorder {
|
||||
packetConsumer.accept(i6px.packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package org.kne.cloud.network.srv6;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.kne.cloud.network.ipv6.FlowSession;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet;
|
||||
|
||||
public class SRv6PacketSeqMarker {
|
||||
private Map<FlowSession,AtomicLong> flowseqMap=new ConcurrentHashMap<FlowSession,AtomicLong>();
|
||||
public void mark(IPv6Packet ipp) {
|
||||
AtomicLong nal=new AtomicLong();
|
||||
AtomicLong rez=flowseqMap.putIfAbsent(ipp.getFlowSession(), nal);
|
||||
if(rez==null) {
|
||||
rez=nal;
|
||||
}
|
||||
ipp.setFlowSeqMark(rez.getAndIncrement());
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user