import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply;
public void mapRegisterWithMapNotify() throws SocketTimeoutException {
cleanUP();
- mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), NULL_AUTH_KEY);
+ mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), NULL_AUTH_KEY);
sleepForSeconds(1);
sendPacket(mapRegisterPacketWithNotify);
MapNotify reply = receiveMapNotify();
public void mapRegisterWithMapNotifyAndMapRequest() throws SocketTimeoutException {
cleanUP();
- Eid eid = LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
MapReply mapReply = registerAddressAndQuery(eid);
public void mapRequestMapRegisterAndMapRequest() throws SocketTimeoutException {
cleanUP();
- Eid eid = LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
sleepForSeconds(1);
public void testMapRegisterDosntOverwritesOtherSubKeys() throws SocketTimeoutException {
cleanUP();
- Eid eid = LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
SimpleAddress rloc1Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.1")));
Rloc rloc1 = LispAddressUtil.asKeyValueAddress("subkey1", rloc1Value);
SimpleAddress rloc2Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.2")));
public void testMapRegisterOverwritesSameSubkey() throws SocketTimeoutException {
cleanUP();
- Eid eid = LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
SimpleAddress rloc1Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.1")));
Rloc rloc1 = LispAddressUtil.asKeyValueAddress("subkey1", rloc1Value);
SimpleAddress rloc2Value = new SimpleAddress(new IpAddress(new Ipv4Address("4.3.2.2")));
public void testMapRegisterOverwritesNoSubkey() throws SocketTimeoutException {
cleanUP();
mapService.setMappingOverwrite(true);
- Eid eid = LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
Rloc rloc1Value = LispAddressUtil.asIpv4Rloc("4.3.2.1");
Rloc rloc2Value = LispAddressUtil.asIpv4Rloc("4.3.2.2");
MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
public void testMapRegisterDoesntOverwritesNoSubkey() throws SocketTimeoutException {
cleanUP();
mapService.setMappingOverwrite(false);
- Eid eid = LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
Rloc rloc1Value = LispAddressUtil.asIpv4Rloc("4.3.2.1");
Rloc rloc2Value = LispAddressUtil.asIpv4Rloc("4.3.2.2");
MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value);
public void registerQueryRegisterWithSmr() throws SocketTimeoutException {
cleanUP();
lms.setShouldUseSmr(true);
- mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), NULL_AUTH_KEY);
+ mapService.addAuthenticationKey(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), NULL_AUTH_KEY);
sleepForSeconds(1);
sendPacket(mapRegisterPacketWithNotify);
Eid sourceEid = smr.getSourceEid().getEid();
assertTrue(LispAddressUtil.asIpv4Eid("153.16.254.1").equals(sourceEid));
Eid smrEid = smr.getEidItem().get(0).getEid();
- assertTrue(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32").equals(smrEid));
+ assertTrue(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32").equals(smrEid));
}
// --------------------- Northbound Tests ---------------------------
public void eidPrefixLookupIPv4() throws SocketTimeoutException {
cleanUP();
- runPrefixTest(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/16"), LispAddressUtil.asIpv4PrefixEid("1.2.3.2/32"),
- LispAddressUtil.asIpv4PrefixEid("1.1.1.1/32"));
+ runPrefixTest(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/16"),
+ LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.2/32"),
+ LispAddressUtil.asIpv4PrefixBinaryEid("1.1.1.1/32"));
}
public void eidPrefixLookupIPv6() throws SocketTimeoutException {
cleanUP();
- runPrefixTest(LispAddressUtil.asIpv6PrefixEid("1:2:3:4:5:6:7:8/64"),
- LispAddressUtil.asIpv6PrefixEid("1:2:3:4:5:1:2:3/128"),
- LispAddressUtil.asIpv6PrefixEid("1:2:3:1:2:3:1:2/128"));
+ runPrefixTest(LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:4:5:6:7:8/64"),
+ LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:4:5:1:2:3/128"),
+ LispAddressUtil.asIpv6PrefixBinaryEid("1:2:3:1:2:3:1:2/128"));
}
private void runPrefixTest(Eid registerEID, Eid matchedAddress, Eid unMatchedAddress)
String ipPrefix2 = ipString2 + "/24";
Eid srcDst = LispAddressUtil.asSrcDstEid(ipString1, ipString2, 24, 24, 0);
- registerAddress(LispAddressUtil.asIpv4PrefixEid(ipPrefix2));
+ registerAddress(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2));
registerAddress(srcDst);
// exact match
assertEquals(ipPrefix2, receivedAddr2.getIpv4Prefix().getValue());
// srcEid/dstEid match
- reply = queryForAddress(LispAddressUtil.asIpv4PrefixEid("20.20.20.1/32"), "10.10.10.1");
+ reply = queryForAddress(LispAddressUtil.asIpv4PrefixBinaryEid("20.20.20.1/32"), "10.10.10.1");
fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
- assertEquals(Ipv4PrefixAfi.class, fromNetwork.getAddressType());
+ assertEquals(Ipv4PrefixBinaryAfi.class, fromNetwork.getAddressType());
- Ipv4Prefix ipAddr2 = (Ipv4Prefix) fromNetwork.getAddress();
- assertEquals(ipPrefix2, ipAddr2.getIpv4Prefix().getValue());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2), fromNetwork);
// dstEid match only
- reply = queryForAddress(LispAddressUtil.asIpv4PrefixEid("20.20.20.1/32"), "1.2.3.4");
+ reply = queryForAddress(LispAddressUtil.asIpv4PrefixBinaryEid("20.20.20.1/32"), "1.2.3.4");
fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
- assertEquals(Ipv4PrefixAfi.class, fromNetwork.getAddressType());
+ assertEquals(Ipv4PrefixBinaryAfi.class, fromNetwork.getAddressType());
- ipAddr2 = (Ipv4Prefix) fromNetwork.getAddress();
- assertEquals(ipPrefix2, ipAddr2.getIpv4Prefix().getValue());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid(ipPrefix2), fromNetwork);
}
@Test
public void mapRequestMapRegisterAndMapRequestTestTimeout() throws SocketTimeoutException {
cleanUP();
- Eid eid = LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
sleepForSeconds(1);
MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
public void mapRequestMapRegisterAndMapRequestTestNativelyForwardTimeoutResponse() throws Exception {
cleanUP();
- Eid eid = LispAddressUtil.asIpv6PrefixEid("1.2.3.4/32");
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32");
MapRequest mapRequest = createMapRequest(eid);
testTTLBeforeRegister(mapRequest);
}
private MapRequest createNonProxyMapRequest(String eid, Rloc adLcaf) throws SocketTimeoutException {
- MapRegister mr = createMapRegister(LispAddressUtil.asIpv4PrefixEid(eid));
+ MapRegister mr = createMapRegister(LispAddressUtil.asIpv4PrefixBinaryEid(eid));
LocatorRecord record = new LocatorRecordBuilder(mr.getMappingRecordItem().get(0).getMappingRecord()
.getLocatorRecord().get(0)).setRloc(adLcaf).build();
mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().set(0, record);
sendMapRegister(mr);
assertMapNotifyReceived();
- MapRequest mapRequest = createMapRequest(LispAddressUtil.asIpv4PrefixEid(eid));
+ MapRequest mapRequest = createMapRequest(LispAddressUtil.asIpv4PrefixBinaryEid(eid));
MapRequestBuilder builder = new MapRequestBuilder(mapRequest);
builder.setPitr(true);
mapRequest = builder.build();
private Set<Eid> prepareExpectedEid(final String ... hosts) {
final Set<Eid> eids = new HashSet<>();
for (String host : hosts) {
- eids.add(LispAddressUtil.asIpv4PrefixEid(host + "/" + IP_MASK, new InstanceIdType(MultiSiteScenarioUtil
- .VNI2)));
+ eids.add(LispAddressUtil.asIpv4PrefixBinaryEid(host + "/" + IP_MASK,
+ new InstanceIdType(MultiSiteScenarioUtil.VNI2)));
}
return eids;
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.lisp.serializer.address;
+
+import com.google.common.net.InetAddresses;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4Serializer.Length;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinaryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public final class Ipv4PrefixBinarySerializer extends LispAddressSerializer {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(Ipv4PrefixBinarySerializer.class);
+
+ private static final Ipv4PrefixBinarySerializer INSTANCE = new Ipv4PrefixBinarySerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private Ipv4PrefixBinarySerializer() {
+ }
+
+ public static Ipv4PrefixBinarySerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.IPV4; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return Length.IPV4; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.IpV4.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) lispAddress.getAddress();
+ buffer.put(prefix.getIpv4AddressBinary().getValue());
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, SimpleAddress address) {
+ buffer.put(InetAddresses.forString(MaskUtil.getAddressStringForIpPrefix(address.getIpPrefix())).getAddress());
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ byte[] ipBuffer = new byte[4];
+ buffer.get(ipBuffer);
+ Ipv4PrefixBinary prefix = new Ipv4PrefixBinaryBuilder()
+ .setIpv4AddressBinary(new Ipv4AddressBinary(ipBuffer)).setIpv4MaskLength(ctx.getMaskLen()).build();
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(Ipv4PrefixBinaryAfi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(prefix);
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ throw new LispSerializationException("RLOCs should not be deserialized into prefixes!");
+ }
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ byte[] ipBuffer = new byte[4];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ LOG.debug("Unknown host {}", ipBuffer, e);
+ }
+ return new SimpleAddress(new IpPrefix(new Ipv4Prefix(address.getHostAddress() + "/" + ctx.getMaskLen())));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.lisp.serializer.address;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6Serializer.Length;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv6AddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinaryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.net.InetAddresses;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public final class Ipv6PrefixBinarySerializer extends LispAddressSerializer {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(Ipv6PrefixBinarySerializer.class);
+
+ private static final Ipv6PrefixBinarySerializer INSTANCE = new Ipv6PrefixBinarySerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private Ipv6PrefixBinarySerializer() {
+ }
+
+ public static Ipv6PrefixBinarySerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.IPV6; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return Length.IPV6; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.IpV6.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ Ipv6PrefixBinary prefix = (Ipv6PrefixBinary) lispAddress.getAddress();
+ buffer.put(prefix.getIpv6AddressBinary().getValue());
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, IpPrefix prefix) {
+ buffer.put(InetAddresses.forString(prefix.getIpv6Prefix().getValue()).getAddress());
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ byte[] ipBuffer = new byte[16];
+ buffer.get(ipBuffer);
+ Ipv6PrefixBinary prefix = new Ipv6PrefixBinaryBuilder()
+ .setIpv6AddressBinary(new Ipv6AddressBinary(ipBuffer)).setIpv6MaskLength(ctx.getMaskLen()).build();
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(Ipv6PrefixBinaryAfi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(prefix);
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ throw new LispSerializationException("RLOCs should not be deserialized into prefixes!");
+ }
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ byte[] ipBuffer = new byte[16];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ LOG.debug("Unknown host {}", ipBuffer, e);
+ }
+ return new SimpleAddress(new IpPrefix(new Ipv6Prefix(address.getHostAddress() + "/" + ctx.getMaskLen())));
+ }
+}
import org.opendaylight.lispflowmapping.lisp.serializer.address.ExplicitLocatorPathSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.InstanceIdSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4BinarySerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4PrefixBinarySerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4PrefixSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6BinarySerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6PrefixBinarySerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6PrefixSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6Serializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.KeyValueAddressSerializer;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4BinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6BinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
/**
* Factory for LispAddress (de)serializers
addressTypeToSerializerMap.put(Ipv4Afi.class, Ipv4Serializer.getInstance());
addressTypeToSerializerMap.put(Ipv4BinaryAfi.class, Ipv4BinarySerializer.getInstance());
addressTypeToSerializerMap.put(Ipv4PrefixAfi.class, Ipv4PrefixSerializer.getInstance());
+ addressTypeToSerializerMap.put(Ipv4PrefixBinaryAfi.class, Ipv4PrefixBinarySerializer.getInstance());
addressTypeToSerializerMap.put(Ipv6Afi.class, Ipv6Serializer.getInstance());
addressTypeToSerializerMap.put(Ipv6BinaryAfi.class, Ipv6BinarySerializer.getInstance());
addressTypeToSerializerMap.put(Ipv6PrefixAfi.class, Ipv6PrefixSerializer.getInstance());
+ addressTypeToSerializerMap.put(Ipv6PrefixBinaryAfi.class, Ipv6PrefixBinarySerializer.getInstance());
addressTypeToSerializerMap.put(MacAfi.class, MacSerializer.getInstance());
addressTypeToSerializerMap.put(DistinguishedNameAfi.class, DistinguishedNameSerializer.getInstance());
addressTypeToSerializerMap.put(Lcaf.class, LcafSerializer.getInstance());
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4BinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6BinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
/**
* This class contains static HashMaps of AFIs and LCAF types to LispAddressFamily identities
afiToAddressTypeMap = new HashMap<Short, Class<? extends LispAddressFamily>>();
afiToAddressTypeMap.put((short) 0, NoAddressAfi.class);
afiToAddressTypeMap.put((short) AddressFamily.IpV4.getIntValue(), Ipv4BinaryAfi.class);
- afiToAddressTypeMap.put((short) (AddressFamily.IpV4.getIntValue() * -1), Ipv4PrefixAfi.class);
+ afiToAddressTypeMap.put((short) (AddressFamily.IpV4.getIntValue() * -1), Ipv4PrefixBinaryAfi.class);
afiToAddressTypeMap.put((short) AddressFamily.IpV6.getIntValue(), Ipv6BinaryAfi.class);
- afiToAddressTypeMap.put((short) (AddressFamily.IpV6.getIntValue() * -1), Ipv6PrefixAfi.class);
+ afiToAddressTypeMap.put((short) (AddressFamily.IpV6.getIntValue() * -1), Ipv6PrefixBinaryAfi.class);
afiToAddressTypeMap.put((short) AddressFamily.DistinguishedName.getIntValue(), DistinguishedNameAfi.class);
afiToAddressTypeMap.put((short) AddressFamily.AsNumber.getIntValue(), AsNumberAfi.class);
afiToAddressTypeMap.put((short) AddressFamily.LispCanonicalAddressFormat.getIntValue(), Lcaf.class);
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop.LrsBits;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
} else if (addr instanceof Ipv4Prefix) {
prefix = "ipv4" + PREFIX_SEPARATOR;
address = getStringFromIpv4Prefix(dst, (Ipv4Prefix) addr);
+ } else if (addr instanceof Ipv4PrefixBinary) {
+ prefix = "ipv4" + PREFIX_SEPARATOR;
+ address = getStringFromIpv4PrefixBinary(dst, (Ipv4PrefixBinary) addr);
} else if (addr instanceof Ipv6) {
prefix = "ipv6" + PREFIX_SEPARATOR;
address = getStringFromIpv6(dst, (Ipv6) addr);
} else if (addr instanceof Ipv6Prefix) {
prefix = "ipv6" + PREFIX_SEPARATOR;
address = getStringFromIpv6Prefix(dst, (Ipv6Prefix) addr);
+ } else if (addr instanceof Ipv6PrefixBinary) {
+ prefix = "ipv6" + PREFIX_SEPARATOR;
+ address = getStringFromIpv6PrefixBinary(dst, (Ipv6PrefixBinary) addr);
} else if (addr instanceof Mac) {
prefix = "mac" + PREFIX_SEPARATOR;
address = getStringFromMac(dst, (Mac) addr);
return getPrefixString(dst, prefix);
}
+ protected static String getStringFromIpv4PrefixBinary(Destination dst, Ipv4PrefixBinary addr) {
+ // AFI = 1; IPv4
+ try {
+ StringBuilder prefixBuilder = new StringBuilder(InetAddresses.toAddrString(
+ Inet4Address.getByAddress(addr.getIpv4AddressBinary().getValue())));
+ prefixBuilder.append('/');
+ prefixBuilder.append(addr.getIpv4MaskLength().toString());
+ return getPrefixString(dst, prefixBuilder.toString());
+ } catch (UnknownHostException e) {
+ LOG.debug("Cannot convert binary IPv4 prefix to string", e);
+ }
+ return null;
+ }
+
protected static String getStringFromIpv6(Destination dst, Ipv6 addr) {
// AFI = 2; IPv6
return addr.getIpv6().getValue();
return addr.getIpv6Prefix().getValue();
}
+ protected static String getStringFromIpv6PrefixBinary(Destination dst, Ipv6PrefixBinary addr) {
+ // AFI = 2; IPv5
+ try {
+ StringBuilder prefixBuilder = new StringBuilder(InetAddresses.toAddrString(
+ Inet6Address.getByAddress(addr.getIpv6AddressBinary().getValue())));
+ prefixBuilder.append('/');
+ prefixBuilder.append(addr.getIpv6MaskLength().toString());
+ return getPrefixString(dst, prefixBuilder.toString());
+ } catch (UnknownHostException e) {
+ LOG.debug("Cannot convert binary IPv6 prefix to string", e);
+ }
+ return null;
+ }
+
protected static String getStringFromDistinguishedName(Destination dst, DistinguishedName addr) {
// AFI = 17; Distinguished Name
return addr.getDistinguishedName().getValue();
*/
package org.opendaylight.lispflowmapping.lisp.util;
+import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
import java.net.Inet4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv6AddressBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4BinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6BinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4BinaryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinaryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6BinaryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinaryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
return builder.build();
}
+ public static Eid toEid(Ipv4PrefixBinary prefix, InstanceIdType vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv4PrefixBinaryAfi.class);
+ builder.setVirtualNetworkId(vni);
+ builder.setAddress((Address) prefix);
+ return builder.build();
+ }
+
+ public static Eid toEid(Ipv6PrefixBinary prefix, InstanceIdType vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv6PrefixBinaryAfi.class);
+ builder.setVirtualNetworkId(vni);
+ builder.setAddress((Address) prefix);
+ return builder.build();
+ }
+
public static Eid toEid(Ipv4Address address, InstanceIdType vni) {
EidBuilder builder = new EidBuilder();
builder.setAddressType(Ipv4Afi.class);
}
public static Eid asIpv4PrefixEid(String prefix) {
- return toEid(new Ipv4Prefix(prefix), null);
+ return asIpv4PrefixEid(prefix, null);
}
public static Eid asIpv4PrefixEid(final String prefix, final InstanceIdType iiType) {
return toEid(new Ipv4Prefix(prefix), iiType);
}
+ public static Eid asIpv4PrefixBinaryEid(final String prefix) {
+ return asIpv4PrefixBinaryEid(prefix, null);
+ }
+
+ public static Eid asIpv4PrefixBinaryEid(final String prefix, final InstanceIdType iiType) {
+ String address = MaskUtil.getPrefixAddress(prefix);
+ short mask = Short.valueOf(MaskUtil.getPrefixMask(prefix));
+ byte[] ipv4 = InetAddresses.forString(address).getAddress();
+ return toEid(new Ipv4PrefixBinaryBuilder().setIpv4AddressBinary(new Ipv4AddressBinary(ipv4))
+ .setIpv4MaskLength(mask).build(), iiType);
+ }
+
public static Eid asIpv4Eid(String address) {
return toEid(new Ipv4AddressBinary(InetAddresses.forString(address).getAddress()), null);
}
return toEid(new Ipv6AddressBinary(InetAddresses.forString(address).getAddress()), null);
}
+ public static Eid asIpv6PrefixBinaryEid(final String prefix) {
+ return asIpv6PrefixBinaryEid(prefix, null);
+ }
+
+ public static Eid asIpv6PrefixBinaryEid(final String prefix, final InstanceIdType iiType) {
+ String address = MaskUtil.getPrefixAddress(prefix);
+ short mask = Short.valueOf(MaskUtil.getPrefixMask(prefix));
+ byte[] ipv6 = InetAddresses.forString(address).getAddress();
+ return toEid(new Ipv6PrefixBinaryBuilder().setIpv6AddressBinary(new Ipv6AddressBinary(ipv6))
+ .setIpv6MaskLength(mask).build(), iiType);
+ }
+
public static Eid asIpv4Eid(String address, long vni) {
return toEid(new Ipv4AddressBinary(InetAddresses.forString(address).getAddress()), new InstanceIdType(vni));
}
return builder.build();
}
+ public static Eid asIpv4PrefixBinaryEid(Eid eid, byte[] address, short mask) {
+ Preconditions.checkArgument(address.length == 4,
+ "asIpv4PrefixBinaryEid called with incorrect length byte array ({})", address.length);
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv4PrefixBinaryAfi.class);
+ builder.setVirtualNetworkId(eid.getVirtualNetworkId());
+ builder.setAddress(new Ipv4PrefixBinaryBuilder().setIpv4AddressBinary(new Ipv4AddressBinary(address))
+ .setIpv4MaskLength(mask).build());
+ return builder.build();
+ }
+
+ public static Eid asIpv6PrefixBinaryEid(Eid eid, byte[] address, short mask) {
+ Preconditions.checkArgument(address.length == 16,
+ "asIpv6PrefixBinaryEid called with incorrect length byte array ({})", address.length);
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv6PrefixBinaryAfi.class);
+ builder.setVirtualNetworkId(eid.getVirtualNetworkId());
+ builder.setAddress(new Ipv6PrefixBinaryBuilder().setIpv6AddressBinary(new Ipv6AddressBinary(address))
+ .setIpv6MaskLength(mask).build());
+ return builder.build();
+ }
+
public static Eid asServicePathEid(long vni, long servicePathId, short serviceIndex) {
EidBuilder eb = new EidBuilder();
eb.setAddressType(ServicePathLcaf.class);
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
public static boolean isMaskable(Address address) {
- if (address instanceof Ipv4Prefix || address instanceof Ipv6Prefix || address instanceof SourceDestKey) {
+ if (address instanceof Ipv4Prefix || address instanceof Ipv6Prefix
+ || address instanceof Ipv4PrefixBinary || address instanceof Ipv6PrefixBinary
+ || address instanceof SourceDestKey) {
return true;
} else if (address instanceof InstanceId) {
return isMaskable(((InstanceId)address).getInstanceId().getAddress());
return slash;
}
- private static String getPrefixAddress(final String prefix) {
+ protected static String getPrefixAddress(final String prefix) {
return prefix.substring(0, slashPosition(prefix));
}
- private static String getPrefixMask(final String prefix) {
+ protected static String getPrefixMask(final String prefix) {
return prefix.substring(slashPosition(prefix) + 1);
}
public static Eid normalize(Eid eid, short mask) {
Address address = eid.getAddress();
try {
- if (address instanceof Ipv4Prefix) {
+ if (address instanceof Ipv4PrefixBinary) {
+ byte[] addr = ((Ipv4PrefixBinary) address).getIpv4AddressBinary().getValue();
+ return LispAddressUtil.asIpv4PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
+ } else if (address instanceof Ipv6PrefixBinary) {
+ byte[] addr = ((Ipv6PrefixBinary) address).getIpv6AddressBinary().getValue();
+ return LispAddressUtil.asIpv6PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
+ } else if (address instanceof Ipv4Prefix) {
final String addr = getPrefixAddress(((Ipv4Prefix)address).getIpv4Prefix().getValue());
InetAddress normalized = normalizeIP(InetAddresses.forString(addr), mask);
return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address)normalized, mask);
public static Eid normalize(Eid eid) {
Address address = eid.getAddress();
try {
- if (address instanceof Ipv4Prefix) {
+ 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);
}
private static InetAddress normalizeIP(InetAddress address, int maskLength) throws UnknownHostException {
- ByteBuffer byteRepresentation = ByteBuffer.wrap(address.getAddress());
+ return InetAddress.getByAddress(normalizeByteArray(address.getAddress(), (short) maskLength));
+ }
+
+ private static byte[] normalizeByteArray(byte[] address, short maskLength) {
+ ByteBuffer byteRepresentation = ByteBuffer.wrap(address);
byte b = (byte) 0xff;
int mask = maskLength;
for (int i = 0; i < byteRepresentation.array().length; i++) {
mask -= 8;
}
- return InetAddress.getByAddress(byteRepresentation.array());
+ return byteRepresentation.array();
}
public static int getMaxMask(Address address) {
- if (address instanceof Ipv4 || address instanceof Ipv4Prefix) {
+ if (address instanceof Ipv4 || address instanceof Ipv4Prefix || address instanceof Ipv4Binary
+ || address instanceof Ipv4PrefixBinary) {
return IPV4_MAX_MASK;
- } else if (address instanceof Ipv6 || address instanceof Ipv6Prefix) {
+ } else if (address instanceof Ipv6 || address instanceof Ipv6Prefix || address instanceof Ipv4Binary
+ || address instanceof Ipv6PrefixBinary) {
return IPV6_MAX_MASK;
} else {
return -1;
public static short getMaskForAddress(Address address) {
if (address instanceof Ipv4) {
return IPV4_MAX_MASK;
- } else if (address instanceof Ipv4Binary) {
- return IPV4_MAX_MASK;
} else if (address instanceof Ipv6) {
return IPV6_MAX_MASK;
+ } else if (address instanceof Ipv4Binary) {
+ return IPV4_MAX_MASK;
} else if (address instanceof Ipv6Binary) {
return IPV6_MAX_MASK;
} else if (address instanceof Ipv4Prefix) {
- return Short.parseShort(getPrefixMask(((Ipv4Prefix)address).getIpv4Prefix().getValue()));
+ return Short.parseShort(getPrefixMask(((Ipv4Prefix) address).getIpv4Prefix().getValue()));
} else if (address instanceof Ipv6Prefix) {
- return Short.parseShort(getPrefixMask(((Ipv6Prefix)address).getIpv6Prefix().getValue()));
+ return Short.parseShort(getPrefixMask(((Ipv6Prefix) address).getIpv6Prefix().getValue()));
} else if (address instanceof InstanceId) {
return getMaskForAddress(((InstanceId)address).getInstanceId().getAddress());
+ } else if (address instanceof Ipv4PrefixBinary) {
+ return ((Ipv4PrefixBinary) address).getIpv4MaskLength();
+ } else if (address instanceof Ipv6PrefixBinary) {
+ return ((Ipv6PrefixBinary) address).getIpv6MaskLength();
}
return -1;
}
));
assertEquals(4, mn.getMappingRecordItem().size());
- assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), mn.getMappingRecordItem().get(0)
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), mn.getMappingRecordItem().get(0)
.getMappingRecord().getEid());
- assertEquals(LispAddressUtil.asIpv4PrefixEid("151.16.254.1/32"), mn.getMappingRecordItem().get(2)
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("151.16.254.1/32"), mn.getMappingRecordItem().get(2)
.getMappingRecord().getEid());
assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.11"), mn.getMappingRecordItem().get(1)
.getMappingRecord().getLocatorRecord().get(0).getRloc());
), null);
assertEquals(4, mr.getMappingRecordItem().size());
- assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), mr.getMappingRecordItem().get(0)
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), mr.getMappingRecordItem().get(0)
.getMappingRecord().getEid());
- assertEquals(LispAddressUtil.asIpv4PrefixEid("151.16.254.1/32"), mr.getMappingRecordItem().get(2)
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("151.16.254.1/32"), mr.getMappingRecordItem().get(2)
.getMappingRecord().getEid());
assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.11"), mr.getMappingRecordItem().get(1)
.getMappingRecord().getLocatorRecord().get(0).getRloc());
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+ "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());
- assertEquals("1.2.3.4/32", ((Ipv4Prefix) mr.getMappingRecordItem().get(0)
- .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ 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?
- assertEquals("4.3.0.0/16", ((Ipv4Prefix) mr.getMappingRecordItem().get(1)
- .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ 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());
MapReply mr = MapReplySerializer.getInstance().deserialize(hexToByteBuffer("20 00 00 02 00 00 "
+ "00 00 00 00 00 00 00 00 00 01 00 20 00 00 00 00 "
+ "00 01 01 02 03 04 00 00 00 00 00 10 30 00 00 02 00 01 04 03 00 00"));
- assertEquals("1.2.3.4/32", ((Ipv4Prefix) mr.getMappingRecordItem().get(0)
- .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ 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?
- assertEquals("4.3.0.0/16", ((Ipv4Prefix) mr.getMappingRecordItem().get(1)
- .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ 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());
import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+ "00 01 c0 a8 38 66"));
assertArrayEquals(new byte[] {1, 1, 1, 1},
((Ipv4Binary) mr.getSourceEid().getEid().getAddress()).getIpv4Binary().getValue());
- assertEquals("1.2.3.4/32",
- ((Ipv4Prefix) mr.getEidItem().get(0).getEid().getAddress()).getIpv4Prefix().getValue());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"), mr.getEidItem().get(0).getEid());
}
+ "00 20 00 01 01 02 03 04"));
assertEquals(1, mr.getEidItem().size());
- Eid eid = mr.getEidItem().get(0).getEid();
- assertEquals("1.2.3.4/32", ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"), mr.getEidItem().get(0).getEid());
}
@Test
));
assertEquals(1, mr.getEidItem().size());
- Eid eid = mr.getEidItem().get(0).getEid();
- assertEquals("1.2.3.4/32", ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"), mr.getEidItem().get(0).getEid());
MappingRecord record = mr.getMapReply().getMappingRecord();
- assertEquals("1.2.3.4/32", ((Ipv4Prefix) record.getEid().getAddress()).getIpv4Prefix().getValue());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"), record.getEid());
assertEquals(false, record.isAuthoritative());
assertEquals(Action.NoAction, record.getAction());
assertEquals(0, record.getMapVersion().shortValue());
+ "00 80 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05"));
assertEquals(2, mr.getEidItem().size());
-
- Eid eid = mr.getEidItem().get(0).getEid();
- assertEquals("1.2.3.4/32", ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
-
- eid = mr.getEidItem().get(1).getEid();
- assertEquals("0:0:0:0:0:0:0:5/128", ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"), mr.getEidItem().get(0).getEid());
+ assertEquals(LispAddressUtil.asIpv6PrefixBinaryEid("0:0:0:0:0:0:0:5/128"), mr.getEidItem().get(1).getEid());
}
@Test
import static org.opendaylight.lispflowmapping.southbound.lisp.MapRegisterCacheTestUtil.nonce;
import static org.opendaylight.lispflowmapping.southbound.lisp.MapRegisterCacheTestUtil.siteId;
import static org.opendaylight.lispflowmapping.southbound.lisp.MapRegisterCacheTestUtil.xTRId;
-
import io.netty.channel.socket.DatagramPacket;
+
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+
import junitx.framework.ArrayAssert;
+
import org.apache.commons.lang3.ArrayUtils;
import org.jmock.api.Invocation;
import org.junit.Before;
import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4BinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
handleMapRegisterPacket(mapRegisterPacket);
MappingRecord eidToLocatorRecord = lastMapRegister().getMappingRecordItem().get(0).getMappingRecord();
- assertEquals("2610:d0:ffff:192:0:0:0:1/128",
- ((Ipv6Prefix) eidToLocatorRecord.getEid().getAddress()).getIpv6Prefix().getValue());
- assertEquals(Ipv6PrefixAfi.class, eidToLocatorRecord.getEid().getAddressType());
+ assertEquals(LispAddressUtil.asIpv6PrefixBinaryEid("2610:d0:ffff:192:0:0:0:1/128"),
+ eidToLocatorRecord.getEid());
+ assertEquals(Ipv6PrefixBinaryAfi.class, eidToLocatorRecord.getEid().getAddressType());
assertEquals(LispAddressUtil.asIpv4Rloc("10.0.58.156"), eidToLocatorRecord.getLocatorRecord().get(0).getRloc());
}
handleMapRegisterPacket(mapRegisterPacket);
MappingRecord eidToLocator = lastMapRegister().getMappingRecordItem().get(0).getMappingRecord();
- assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), eidToLocator.getEid());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"), eidToLocator.getEid());
assertEquals(1, eidToLocator.getLocatorRecord().size());
assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.10"), eidToLocator.getLocatorRecord().get(0).getRloc());
List<EidItem> eids = lastMapRequest().getEidItem();
assertEquals(1, eids.size());
Eid lispAddress = eids.get(0).getEid();
- assertEquals(Ipv4PrefixAfi.class, lispAddress.getAddressType());
- assertEquals(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32"), lispAddress);
+ assertEquals(Ipv4PrefixBinaryAfi.class, lispAddress.getAddressType());
+ assertEquals(LispAddressUtil.asIpv4PrefixBinaryEid("1.2.3.4/32"), lispAddress);
assertEquals(0x3d8d2acd39c8d608L, lastMapRequest().getNonce().longValue());
}
handleMapRequestAsByteArray(mapRequestPacket);
assertEquals(LispAddressUtil.asIpv6Eid("2610:d0:ffff:192:0:0:0:1"), lastMapRequest().getSourceEid().getEid());
- assertEquals(LispAddressUtil.asIpv6PrefixEid("2610:d0:ffff:192:0:0:0:2/128"),
+ assertEquals(LispAddressUtil.asIpv6PrefixBinaryEid("2610:d0:ffff:192:0:0:0:2/128"),
lastMapRequest().getEidItem().get(0).getEid());
}