KLALB V3.6.0 写了一半

This commit is contained in:
Administrator
2026-02-27 08:32:03 +08:00
parent 816e672843
commit 620afef715
164 changed files with 8381 additions and 13495 deletions
@@ -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;