use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.
the class HashMapDb method tryRemoveFromTrie.
private void tryRemoveFromTrie(Object key) {
if (key instanceof Eid) {
Eid eid = (Eid) key;
if (eid.getAddress() instanceof Ipv4PrefixBinary) {
Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) eid.getAddress();
ip4Trie.remove(prefix.getIpv4AddressBinary().getValue(), prefix.getIpv4MaskLength());
} else if (eid.getAddress() instanceof Ipv6PrefixBinary) {
Ipv6PrefixBinary prefix = (Ipv6PrefixBinary) eid.getAddress();
ip6Trie.remove(prefix.getIpv6AddressBinary().getValue(), prefix.getIpv6MaskLength());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTestUtil method removePrefixIfNecessary.
static Eid removePrefixIfNecessary(Eid eid) {
EidBuilder eb = new EidBuilder(eid);
Address address = eid.getAddress();
if (address instanceof Ipv4PrefixBinary) {
Ipv4Binary convertedEid = new Ipv4BinaryBuilder().setIpv4Binary(((Ipv4PrefixBinary) address).getIpv4AddressBinary()).build();
return eb.setAddress(convertedEid).setAddressType(Ipv4BinaryAfi.class).build();
} else if (address instanceof Ipv6PrefixBinary) {
Ipv6Binary convertedEid = new Ipv6BinaryBuilder().setIpv6Binary(((Ipv6PrefixBinary) address).getIpv6AddressBinary()).build();
return eb.setAddress(convertedEid).setAddressType(Ipv6BinaryAfi.class).build();
}
return eid;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method deserialize__All.
@Test
public void deserialize__All() throws Exception {
MapReply mr = MapReplySerializer.getInstance().deserialize(hexToByteBuffer("20 00 00 02 00 00 " + "00 00 00 00 00 02 00 00 " + "00 02 02 20 00 00 00 00 " + "00 01 01 02 03 04 01 02 " + "03 04 00 06 00 01 0a 0a " + "0a 0a 04 03 02 01 00 01 " + "00 02 00 01 00 02 00 03 " + "00 04 00 05 00 06 00 07 00 08 00 00 00 00 00 10 30 00 00 02 00 01 04 03 00 00"));
assertEquals(2, mr.getNonce().longValue());
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, ((Ipv4PrefixBinary) mr.getMappingRecordItem().get(0).getMappingRecord().getEid().getAddress()).getIpv4AddressBinary().getValue());
// XXX Why here normalized and other cases not normalized?
assertArrayEquals(new byte[] { 4, 3, 0, 0 }, ((Ipv4PrefixBinary) mr.getMappingRecordItem().get(1).getMappingRecord().getEid().getAddress()).getIpv4AddressBinary().getValue());
assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().isAuthoritative());
assertEquals(true, mr.getMappingRecordItem().get(1).getMappingRecord().isAuthoritative());
assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
assertEquals(Action.NativelyForward, mr.getMappingRecordItem().get(1).getMappingRecord().getAction());
assertEquals(0, mr.getMappingRecordItem().get(0).getMappingRecord().getMapVersion().shortValue());
assertEquals(2, mr.getMappingRecordItem().get(1).getMappingRecord().getMapVersion().shortValue());
assertEquals(32, MaskUtil.getMaskForAddress(mr.getMappingRecordItem().get(0).getMappingRecord().getEid().getAddress()));
assertEquals(16, MaskUtil.getMaskForAddress(mr.getMappingRecordItem().get(1).getMappingRecord().getEid().getAddress()));
assertEquals(2, mr.getMappingRecordItem().get(0).getMappingRecord().getRecordTtl().byteValue());
assertEquals(0, mr.getMappingRecordItem().get(1).getMappingRecord().getRecordTtl().byteValue());
assertArrayEquals(new byte[] { 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8 }, ((Ipv6Binary) mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getRloc().getAddress()).getIpv6Binary().getValue());
assertArrayEquals(new byte[] { 10, 10, 10, 10 }, ((Ipv4Binary) mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc().getAddress()).getIpv4Binary().getValue());
assertEquals(1, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getPriority().byteValue());
assertEquals(2, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getWeight().byteValue());
assertEquals(3, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getMulticastPriority().byteValue());
assertEquals(4, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getMulticastWeight().byteValue());
assertEquals(4, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getPriority().byteValue());
assertEquals(3, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getWeight().byteValue());
assertEquals(2, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getMulticastPriority().byteValue());
assertEquals(1, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getMulticastWeight().byteValue());
assertEquals(true, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).isLocalLocator());
assertEquals(true, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).isRlocProbed());
assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).isRouted());
assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).isLocalLocator());
assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).isRlocProbed());
assertEquals(true, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).isRouted());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method toEid_ipv4PrefixBinary.
/**
* Test
* - {@link LispAddressUtil#toEid(Ipv4PrefixBinary, InstanceIdType)}
* - {@link LispAddressUtil#asIpv4PrefixBinaryEid(String)}
* - {@link LispAddressUtil#asIpv4PrefixBinaryEid(String, InstanceIdType)}
* - {@link LispAddressUtil#asIpv4PrefixBinaryEid(Eid, byte[], short)}
* methods.
*/
@Test
public void toEid_ipv4PrefixBinary() {
Eid eidFromIpv4PrefixBinary = LispAddressUtil.toEid(IPV4_ADDRESS_PREFIX_BINARY_1, INSTANCE_ID_TYPE_TEST);
verifyToEidWithIpv4PrefixBinary(eidFromIpv4PrefixBinary, true, MASK_OK_TEST, Ipv4PrefixBinaryAfi.class);
eidFromIpv4PrefixBinary = LispAddressUtil.asIpv4PrefixBinaryEid(IPV4_ADDRESS_PREFIX_VALUE_TEST);
verifyToEidWithIpv4PrefixBinary(eidFromIpv4PrefixBinary, false, MASK_OK_TEST, Ipv4PrefixBinaryAfi.class);
eidFromIpv4PrefixBinary = LispAddressUtil.asIpv4PrefixBinaryEid(IPV4_ADDRESS_PREFIX_VALUE_TEST, INSTANCE_ID_TYPE_TEST);
verifyToEidWithIpv4PrefixBinary(eidFromIpv4PrefixBinary, true, MASK_OK_TEST, Ipv4PrefixBinaryAfi.class);
eidFromIpv4PrefixBinary = LispAddressUtil.asIpv4PrefixBinaryEid(IPV4_ADDRESS_PREFIX_BINARY_EID_1, IPV4_ADDRESS_BYTES_A_TEST, MASK_OK_TEST);
verifyToEidWithIpv4PrefixBinary(eidFromIpv4PrefixBinary, true, MASK_OK_TEST, Ipv4PrefixBinaryAfi.class);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.
the class MaskUtil method normalize.
public static Eid normalize(Eid eid) {
Address address = eid.getAddress();
try {
if (address instanceof Ipv4PrefixBinary) {
byte[] addr = ((Ipv4PrefixBinary) address).getIpv4AddressBinary().getValue();
short mask = ((Ipv4PrefixBinary) address).getIpv4MaskLength();
return LispAddressUtil.asIpv4PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
} else if (address instanceof Ipv6PrefixBinary) {
byte[] addr = ((Ipv6PrefixBinary) address).getIpv6AddressBinary().getValue();
short mask = ((Ipv6PrefixBinary) address).getIpv6MaskLength();
return LispAddressUtil.asIpv6PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
} else if (address instanceof Ipv4Prefix) {
String[] v4prefix = splitPrefix(((Ipv4Prefix) address).getIpv4Prefix().getValue());
short mask = Short.parseShort(v4prefix[1]);
InetAddress normalized = normalizeIP(InetAddresses.forString(v4prefix[0]), mask);
return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address) normalized, mask);
} else if (address instanceof Ipv6Prefix) {
String[] v6prefix = splitPrefix(((Ipv6Prefix) address).getIpv6Prefix().getValue());
short mask = Short.parseShort(v6prefix[1]);
InetAddress normalized = normalizeIP(InetAddresses.forString(v6prefix[0]), mask);
return LispAddressUtil.asIpv6PrefixEid(eid, (Inet6Address) normalized, mask);
} else if (address instanceof Ipv4) {
return LispAddressUtil.asIpv4PrefixEid(((Ipv4) address).getIpv4(), eid.getVirtualNetworkId());
} else if (address instanceof Ipv6) {
return LispAddressUtil.asIpv6PrefixEid(((Ipv6) address).getIpv6(), eid.getVirtualNetworkId());
} else if (address instanceof InstanceId) {
// TODO - not absolutely necessary, but should be implemented
return eid;
} else if (address instanceof SourceDestKey) {
return normalizeSrcDst(eid);
} else if (address instanceof ServicePath) {
// Build new Service Path eid with service index set to 0
long spi = ((ServicePath) address).getServicePath().getServicePathId().getValue();
long vni = eid.getVirtualNetworkId() != null ? eid.getVirtualNetworkId().getValue() : -1;
return LispAddressUtil.asServicePathEid(vni, spi, (short) 0);
}
} catch (UnknownHostException e) {
LOG.warn("Failed to normalize EID {}, returning original", eid, e);
}
return eid;
}
Aggregations