fixed discovery result save
This commit is contained in:
parent
e8701e2695
commit
0c5f529bf0
|
@ -28,4 +28,33 @@ public class StringConvertor {
|
||||||
return result;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ public class TargetDiscoveryService {
|
||||||
InfraHost newInfraHost = new InfraHost();
|
InfraHost newInfraHost = new InfraHost();
|
||||||
newInfraHost.setIp(StringConvertor.ipToLong(host.getIp()));
|
newInfraHost.setIp(StringConvertor.ipToLong(host.getIp()));
|
||||||
// newInfraHost.setMac(StringConvertor.ipToLong(host.getMac()));
|
// newInfraHost.setMac(StringConvertor.ipToLong(host.getMac()));
|
||||||
newInfraHost.setMac(123123123);
|
newInfraHost.setMac(StringConvertor.macStrToLong(host.getMac()));
|
||||||
newInfraHost.setOs(infraOS);
|
newInfraHost.setOs(infraOS);
|
||||||
newInfraHost.setInfraType(typeHost);
|
newInfraHost.setInfraType(typeHost);
|
||||||
newInfraHost.setProbe(probe);
|
newInfraHost.setProbe(probe);
|
||||||
|
|
|
@ -158,10 +158,16 @@ public class TargetDiscoveryServiceTest {
|
||||||
String nnn = o.getClass().getSimpleName();
|
String nnn = o.getClass().getSimpleName();
|
||||||
System.out.println(nnn);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user