rNew = new ArrayList<>();
for (VirtualNetworkRoute r : routes) {
rCurrent.add(r.toString());
}
for (VirtualNetworkRoute r : cfg.routes) {
rNew.add(r.toString());
}
Collections.sort(rCurrent);
Collections.sort(rNew);
boolean routesEqual = rCurrent.equals(rNew);
if (this.nwid != cfg.nwid) {
Log.i(TAG, "nwid Changed. Old: " + Long.toHexString(this.nwid) + " (" + Long.toString(this.nwid) + "), " +
"New: " + Long.toHexString(cfg.nwid) + " (" + Long.toString(cfg.nwid) + ")");
}
if (this.mac != cfg.mac) {
Log.i(TAG, "MAC Changed. Old: " + Long.toHexString(this.mac) + ", New: " + Long.toHexString(cfg.mac));
}
if (!this.name.equals(cfg.name)) {
Log.i(TAG, "Name Changed. Old: " + this.name + " New: "+ cfg.name);
}
if (!this.type.equals(cfg.type)) {
Log.i(TAG, "TYPE changed. Old " + this.type + ", New: " + cfg.type);
}
if (this.mtu != cfg.mtu) {
Log.i(TAG, "MTU Changed. Old: " + this.mtu + ", New: " + cfg.mtu);
}
if (this.dhcp != cfg.dhcp) {
Log.i(TAG, "DHCP Flag Changed. Old: " + this.dhcp + ", New: " + cfg.dhcp);
}
if (this.bridge != cfg.bridge) {
Log.i(TAG, "Bridge Flag Changed. Old: " + this.bridge + ", New: " + cfg.bridge);
}
if (this.broadcastEnabled != cfg.broadcastEnabled) {
Log.i(TAG, "Broadcast Flag Changed. Old: "+ this.broadcastEnabled +", New: " + this.broadcastEnabled);
}
if (this.portError != cfg.portError) {
Log.i(TAG, "Port Error Changed. Old: " + this.portError + ", New: " + this.portError);
}
if (this.enabled != cfg.enabled) {
Log.i(TAG, "Enabled Changed. Old: " + this.enabled + ", New: " + this.enabled);
}
if (!aaEqual) {
Log.i(TAG, "Assigned Addresses Changed");
Log.i(TAG, "Old:");
for (String s : aaCurrent) {
Log.i(TAG, " " + s);
}
Log.i(TAG, "New:");
for (String s : aaNew) {
Log.i(TAG, " " +s);
}
}
if (!routesEqual) {
Log.i(TAG, "Managed Routes Changed");
Log.i(TAG, "Old:");
for (String s : rCurrent) {
Log.i(TAG, " " + s);
}
Log.i(TAG, "New:");
for (String s : rNew) {
Log.i(TAG, " " + s);
}
}
boolean dnsEquals = false;
if (this.dns == null || cfg.dns == null) {
dnsEquals = true;
} else if (this.dns != null) {
dnsEquals = this.dns.equals(cfg.dns);
}
return this.nwid == cfg.nwid &&
this.mac == cfg.mac &&
this.name.equals(cfg.name) &&
this.status.equals(cfg.status) &&
this.type.equals(cfg.type) &&
this.mtu == cfg.mtu &&
this.dhcp == cfg.dhcp &&
this.bridge == cfg.bridge &&
this.broadcastEnabled == cfg.broadcastEnabled &&
this.portError == cfg.portError &&
this.enabled == cfg.enabled &&
dnsEquals &&
aaEqual && routesEqual;
}
public int compareTo(VirtualNetworkConfig cfg) {
if(cfg.nwid == this.nwid) {
return 0;
} else {
return this.nwid > cfg.nwid ? 1 : -1;
}
}
/**
* 64-bit ZeroTier network ID
*/
public final long networkId() {
return nwid;
}
/**
* Ethernet MAC (40 bits) that should be assigned to port
*/
public final long macAddress() {
return mac;
}
/**
* Network name (from network configuration master)
*/
public final String name() {
return name;
}
/**
* Network configuration request status
*/
public final VirtualNetworkStatus networkStatus() {
return status;
}
/**
* Network type
*/
public final VirtualNetworkType networkType() {
return type;
}
/**
* Maximum interface MTU
*/
public final int mtu() {
return mtu;
}
/**
* If the network this port belongs to indicates DHCP availability
*
* This is a suggestion. The underlying implementation is free to ignore it
* for security or other reasons. This is simply a netconf parameter that
* means 'DHCP is available on this network.'
*/
public final boolean isDhcpAvailable() {
return dhcp;
}
/**
* If this port is allowed to bridge to other networks
*
* This is informational. If this is false, bridged packets will simply
* be dropped and bridging won't work.
*/
public final boolean isBridgeEnabled() {
return bridge;
}
/**
* If true, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic
*/
public final boolean broadcastEnabled() {
return broadcastEnabled;
}
/**
* If the network is in PORT_ERROR state, this is the error most recently returned by the port config callback
*/
public final int portError() {
return portError;
}
/**
* Network config revision as reported by netconf master
*
* If this is zero, it means we're still waiting for our netconf.
*/
public final long netconfRevision() {
return netconfRevision;
}
/**
* ZeroTier-assigned addresses (in {@link java.net.InetSocketAddress} objects)
*
* For IP, the port number of the sockaddr_XX structure contains the number
* of bits in the address netmask. Only the IP address and port are used.
* Other fields like interface number can be ignored.
*
* This is only used for ZeroTier-managed address assignments sent by the
* virtual network's configuration master.
*/
public final InetSocketAddress[] assignedAddresses() {
return assignedAddresses;
}
/**
* ZeroTier-assigned routes (in {@link com.zerotier.sdk.VirtualNetworkRoute} objects)
*
* @return
*/
public final VirtualNetworkRoute[] routes() { return routes; }
public final VirtualNetworkDNS dns() { return dns; }
}