137 lines
3.6 KiB
Java
137 lines
3.6 KiB
Java
package org.kne.cloud.network.ipv6;
|
|
|
|
import java.net.Inet6Address;
|
|
import java.net.InetAddress;
|
|
import java.util.Objects;
|
|
|
|
|
|
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
|
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
|
import org.kne.cloud.network.monitor.DelayMonitorData;
|
|
import org.kne.cloud.network.monitor.MonitorData;
|
|
|
|
public class RouteItem implements Comparable<RouteItem>,Cloneable{
|
|
private IPv6AddressGroup destination;
|
|
private IPv6Address nexthop;
|
|
private IPv6NetworkLink destlink;
|
|
private String proto;
|
|
private int pre;
|
|
private long cost;
|
|
private String flag;
|
|
private MonitorData monitor;
|
|
private boolean isLoopback;
|
|
public String getFlag() {
|
|
return flag;
|
|
}
|
|
public MonitorData getMonitor() {
|
|
return monitor;
|
|
}
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(cost, destination, destlink, flag, nexthop, pre, proto);
|
|
}
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj)
|
|
return true;
|
|
if (obj == null)
|
|
return false;
|
|
if (getClass() != obj.getClass())
|
|
return false;
|
|
RouteItem other = (RouteItem) obj;
|
|
return cost == other.cost && Objects.equals(destination, other.destination)
|
|
&& Objects.equals(flag, other.flag)
|
|
&& pre == other.pre && Objects.equals(proto, other.proto);
|
|
}
|
|
public RouteItem(IPv6AddressGroup destination, IPv6Address nexthop, IPv6NetworkLink destlink, String proto, int pre,
|
|
long cost,String flag,boolean isLoopback) {
|
|
super();
|
|
this.destination = destination;
|
|
this.nexthop = nexthop;
|
|
this.destlink = destlink;
|
|
this.proto = proto;
|
|
this.pre = pre;
|
|
this.cost = cost;
|
|
this.flag=flag;
|
|
this.isLoopback=isLoopback;
|
|
}
|
|
public RouteItem(IPv6AddressGroup destination, IPv6Address nexthop, IPv6NetworkLink destlink, String proto, int pre,
|
|
long cost,MonitorData monitor,String flag,boolean isLoopback) {
|
|
super();
|
|
this.destination = destination;
|
|
this.nexthop = nexthop;
|
|
this.destlink = destlink;
|
|
this.proto = proto;
|
|
this.pre = pre;
|
|
this.cost = cost;
|
|
this.monitor=monitor;
|
|
this.flag=flag;
|
|
this.isLoopback=isLoopback;
|
|
}
|
|
public IPv6AddressGroup getDestination() {
|
|
return destination;
|
|
}
|
|
public IPv6Address getNexthop() {
|
|
return nexthop;
|
|
}
|
|
public IPv6NetworkLink getDestlink() {
|
|
return destlink;
|
|
}
|
|
public String getProto() {
|
|
return proto;
|
|
}
|
|
public int getPre() {
|
|
return pre;
|
|
}
|
|
public boolean isLoopback() {
|
|
return isLoopback;
|
|
}
|
|
@Override
|
|
public String toString() {
|
|
return getDestination()+"\t"+getProto()+"\t"+getPre()+"\t"+getCost()+"\t"+getFlag()+"\t"+getNexthop()+"\t"+getDestlink().getName();
|
|
}
|
|
public long getCost() {
|
|
return cost;
|
|
}
|
|
/*public boolean checkMatch(IPv6Address ia) {
|
|
return destination.checkMatch(ia);
|
|
}
|
|
public boolean checkMatch(byte[] ia) {
|
|
return destination.checkMatch(ia);
|
|
}*/
|
|
@Override
|
|
public int compareTo(RouteItem o) {
|
|
int v1=destination.compareTo(o.destination);
|
|
if(v1!=0)
|
|
return v1;
|
|
int v2=Integer.compare(pre, o.pre);
|
|
if(v2!=0)
|
|
return v2;
|
|
int v3=Long.compare(cost, o.cost);
|
|
return v3;
|
|
}
|
|
@Override
|
|
public Object clone() {
|
|
try {
|
|
RouteItem ri=(RouteItem) super.clone();
|
|
if(monitor!=null)
|
|
ri.monitor=(MonitorData) monitor.clone();
|
|
return ri;
|
|
} catch (CloneNotSupportedException e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void preSort() {
|
|
if(monitor!=null) {
|
|
cost=((DelayMonitorData)monitor).getOutDelay();
|
|
}
|
|
}
|
|
public boolean ECMPequals(RouteItem prevr) {
|
|
return prevr.getDestination().getPrefixLength()==getDestination().getPrefixLength()&&prevr.getPre()==getPre();
|
|
|
|
}
|
|
|
|
}
|