Skip to content
Snippets Groups Projects
Commit fd1af314 authored by Kanzhe Jiang's avatar Kanzhe Jiang
Browse files

learn ip on ARP reply only and update network address lastseen on all ip packets

parent 80a1d691
No related branches found
No related tags found
No related merge requests found
...@@ -773,7 +773,9 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe ...@@ -773,7 +773,9 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe
devMgrMaps.updateMaps(device); devMgrMaps.updateMaps(device);
writeDeviceToStorage(device, currentDate); writeDeviceToStorage(device, currentDate);
updateStatus(device, true); updateStatus(device, true);
log.debug("New device learned {}", device); if (log.isDebugEnabled()) {
log.debug("New device learned {}", device);
}
} }
private boolean isGratArp(Ethernet eth) { private boolean isGratArp(Ethernet eth) {
...@@ -795,15 +797,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe ...@@ -795,15 +797,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe
} }
} else if (eth.getPayload() instanceof IPv4) { } else if (eth.getPayload() instanceof IPv4) {
IPv4 ipv4 = (IPv4) eth.getPayload(); IPv4 ipv4 = (IPv4) eth.getPayload();
if (ipv4.getPayload() instanceof UDP) { return ipv4.getSourceAddress();
UDP udp = (UDP)ipv4.getPayload();
if (udp.getPayload() instanceof DHCP) {
DHCP dhcp = (DHCP)udp.getPayload();
if (dhcp.getOpCode() == DHCP.OPCODE_REPLY) {
return ipv4.getSourceAddress();
}
}
}
} }
return 0; return 0;
} }
...@@ -881,9 +875,13 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe ...@@ -881,9 +875,13 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe
if (networkAddress != null) { if (networkAddress != null) {
updateNetworkAddressLastSeen = true; updateNetworkAddressLastSeen = true;
} else if (eth != null && (eth.getPayload() instanceof ARP)) { } else if (eth != null && (eth.getPayload() instanceof ARP)) {
networkAddress = new DeviceNetworkAddress(nwSrc, ARP arp = (ARP)eth.getPayload();
// Only learn new MAC-IP mapping on ARP reply
if (arp.getOpCode() == 0x02) {
networkAddress = new DeviceNetworkAddress(nwSrc,
currentDate); currentDate);
newNetworkAddress = true; newNetworkAddress = true;
}
} }
// Also, if this address is currently mapped to a different // Also, if this address is currently mapped to a different
...@@ -913,7 +911,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe ...@@ -913,7 +911,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe
new Object[] {networkAddress, new Object[] {networkAddress,
HexString.toHexString(deviceByNwaddr.getDataLayerAddress()), HexString.toHexString(deviceByNwaddr.getDataLayerAddress()),
HexString.toHexString(device.getDataLayerAddress()), HexString.toHexString(device.getDataLayerAddress()),
eth}); eth.toString()});
} }
} }
...@@ -946,8 +944,8 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe ...@@ -946,8 +944,8 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe
if (newNetworkAddress) { if (newNetworkAddress) {
// add the address // add the address
nd.addNetworkAddress(networkAddress); nd.addNetworkAddress(networkAddress);
log.debug("Device {} added IP {}", log.info("Device {} added IP {}, packet {}",
nd, IPv4.fromIPv4Address(nwSrc)); new Object[] {nd, IPv4.fromIPv4Address(nwSrc), eth.toString()});
} }
if (updateDeviceVlan) { if (updateDeviceVlan) {
...@@ -1544,7 +1542,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe ...@@ -1544,7 +1542,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe
// ******************** // ********************
public boolean readPortChannelConfigFromStorage() { public boolean readPortChannelConfigFromStorage() {
devMgrMaps.clearPortChannelMap(); devMgrMaps.clearPortChannelMap();
try { try {
IResultSet pcResultSet = storageSource.executeQuery( IResultSet pcResultSet = storageSource.executeQuery(
...@@ -2178,20 +2176,20 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe ...@@ -2178,20 +2176,20 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe
deviceManagerAware.add(listener); deviceManagerAware.add(listener);
} }
@Override @Override
public Map<String, Object> getInfo(String type) { public Map<String, Object> getInfo(String type) {
if (!"summary".equals(type)) if (!"summary".equals(type))
return null; return null;
Map<String, Object> info = new HashMap<String, Object>(); Map<String, Object> info = new HashMap<String, Object>();
info.put("# hosts", devMgrMaps.dataLayerAddressDeviceMap.size()); info.put("# hosts", devMgrMaps.dataLayerAddressDeviceMap.size());
info.put("# IP Addresses", devMgrMaps.ipv4AddressDeviceMap.size()); info.put("# IP Addresses", devMgrMaps.ipv4AddressDeviceMap.size());
int num_aps = 0; int num_aps = 0;
for (Map<Integer, Device> devAps : devMgrMaps.switchPortDeviceMap.values()) for (Map<Integer, Device> devAps : devMgrMaps.switchPortDeviceMap.values())
num_aps += devAps.size(); num_aps += devAps.size();
info.put("# attachment points", num_aps); info.put("# attachment points", num_aps);
return info; return info;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment