fixed discovery result save

This commit is contained in:
snoop 2018-04-04 15:49:06 +09:00
parent e8701e2695
commit 0c5f529bf0
3 changed files with 36 additions and 1 deletions

View File

@ -28,4 +28,33 @@ public class StringConvertor {
return result;
}
// https://github.com/Sovietaced/floodlight/blob/master/src/main/java/net/floodlightcontroller/util/MACAddress.java
public static final int MAC_ADDRESS_LENGTH = 6;
public static long macStrToLong(String address) {
String[] elements = address.split(":");
if (elements.length != MAC_ADDRESS_LENGTH) {
throw new IllegalArgumentException(
"Specified MAC Address must contain 12 hex digits" +
" separated pairwise by :'s.");
}
byte[] addressInBytes = new byte[MAC_ADDRESS_LENGTH];
for (int i = 0; i < MAC_ADDRESS_LENGTH; i++) {
String element = elements[i];
addressInBytes[i] = (byte)Integer.parseInt(element, 16);
}
long mac = 0;
for (int i = 0; i < 6; i++) {
long t = (addressInBytes[i] & 0xffL) << ((5 - i) * 8);
mac |= t;
}
return mac;
// return new MACAddress(addressInBytes);
}
}

View File

@ -200,7 +200,7 @@ public class TargetDiscoveryService {
InfraHost newInfraHost = new InfraHost();
newInfraHost.setIp(StringConvertor.ipToLong(host.getIp()));
// newInfraHost.setMac(StringConvertor.ipToLong(host.getMac()));
newInfraHost.setMac(123123123);
newInfraHost.setMac(StringConvertor.macStrToLong(host.getMac()));
newInfraHost.setOs(infraOS);
newInfraHost.setInfraType(typeHost);
newInfraHost.setProbe(probe);

View File

@ -158,10 +158,16 @@ public class TargetDiscoveryServiceTest {
String nnn = o.getClass().getSimpleName();
System.out.println(nnn);
}
@Test
public void macAddrConvert() throws Exception {
String mac = "08:00:27:65:8d:13";
long aa = StringConvertor.macStrToLong(mac);
System.out.println(aa);
}