import javax.inject.Inject;
-
-
-
-
-
//import org.codehaus.jettison.json.JSONException;
//import org.codehaus.jettison.json.JSONObject;
//import org.codehaus.jettison.json.JSONTokener;
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;
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.explicit.locator.path.explicit.locator.path.HopBuilder;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
}
// ------------------------------- LCAF Tests ---------------------------
-/*
+
@Test
public void registerAndQuery__SrcDestLCAF() throws SocketTimeoutException {
cleanUP();
- String ipString = "10.20.30.200";
+ String ipPrefix = "10.20.30.200/32";
String macString = "01:02:03:04:05:06";
- org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4 addrToSend1 = LispAddressUtil.asPrimitiveIPv4AfiPrefix(ipString, 32);
- org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac addrToSend2 = LispAddressUtil.asPrimitiveMacAfiAddress(macString);
- LcafSourceDestAddrBuilder builder = new LcafSourceDestAddrBuilder();
- builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
- builder.setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
- builder.setSrcMaskLength((short) 32);
- builder.setDstMaskLength((short) 0);
- builder.setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(addrToSend1).build());
- builder.setDstAddress(new DstAddressBuilder().setPrimitiveAddress(addrToSend2).build());
-
- MapReply reply = registerAddressAndQuery(builder.build());
+
+ SourceDestKeyBuilder builder = new SourceDestKeyBuilder();
+ builder.setSource(new SimpleAddress(new IpPrefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix(ipPrefix))));
+ builder.setDest(new SimpleAddress(new MacAddress(macString)));
+
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(SourceDestKeyLcaf.class);
+ eb.setVirtualNetworkId(null);
+ eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
+ .setSourceDestKey(builder.build()).build());
+
+ MapReply reply = registerAddressAndQuery(eb.build());
Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
- assertTrue(fromNetwork.getAddress() instanceof LcafSourceDest);
- LcafSourceDest sourceDestFromNetwork = (LcafSourceDest) fromNetwork.getAddress();
+ assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
+ SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
- LispAFIAddress receivedAddr1 = LispAddressUtil.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getSrcAddress().getPrimitiveAddress());
- LispAFIAddress receivedAddr2 = LispAddressUtil.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getDstAddress().getPrimitiveAddress());
+ SimpleAddress receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource();
+ SimpleAddress receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest();
- assertTrue(receivedAddr1 instanceof LispIpv4Address);
- assertTrue(receivedAddr2 instanceof LispMacAddress);
+ assertNotNull(receivedAddr1.getIpPrefix().getIpv4Prefix());
+ assertNotNull(receivedAddr2.getMacAddress());
- LispIpv4Address receivedIP = (LispIpv4Address) receivedAddr1;
- LispMacAddress receivedMAC = (LispMacAddress) receivedAddr2;
+ IpPrefix receivedIP = receivedAddr1.getIpPrefix();
+ MacAddress receivedMAC = receivedAddr2.getMacAddress();
- assertEquals(ipString, receivedIP.getIpv4Address().getValue());
- assertEquals(macString, receivedMAC.getMacAddress().getValue());
+ assertEquals(ipPrefix, receivedIP.getIpv4Prefix().getValue());
+ assertEquals(macString, receivedMAC.getValue());
}
-*/
+
@Test
public void registerAndQuery__SrcDestLCAFOverlap() throws SocketTimeoutException {
cleanUP();
assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
- IpPrefix receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource();
- IpPrefix receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest();
+ IpPrefix receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource().getIpPrefix();
+ IpPrefix receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest().getIpPrefix();
assertNotNull(receivedAddr1.getIpv4Prefix());
assertNotNull(receivedAddr2.getIpv4Prefix());
protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
SourceDestKey sdk = (SourceDestKey) lispAddress.getAddress();
buffer.putShort((short) 0);
- buffer.put((byte) MaskUtil.getMaskForIpPrefix(sdk.getSourceDestKey().getSource()));
- buffer.put((byte) MaskUtil.getMaskForIpPrefix(sdk.getSourceDestKey().getDest()));
+ short srcMaskLength = MaskUtil.getMaskForAddress(sdk.getSourceDestKey().getSource());
+ short dstMaskLength = MaskUtil.getMaskForAddress(sdk.getSourceDestKey().getDest());
+ // TODO need to use LispAddressSerializerContext.MASK_LEN_MISSING everywhere instead of -1 but move that from
+ // LispAddressSerializerContext to some more generic place, maybe
+ // org.opendaylight.lispflowmammping.type.Constants
+ if (srcMaskLength == -1) {
+ srcMaskLength = 0;
+ }
+ if (dstMaskLength == -1) {
+ dstMaskLength = 0;
+ }
+ buffer.put((byte) srcMaskLength);
+ buffer.put((byte) dstMaskLength);
SimpleAddressSerializer.getInstance().serialize(buffer, new SimpleAddress(sdk.getSourceDestKey().getSource()));
SimpleAddressSerializer.getInstance().serialize(buffer, new SimpleAddress(sdk.getSourceDestKey().getDest()));
}
ctx.setMaskLen(dstMaskLength);
SimpleAddress dstAddress = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
SourceDestKeyBuilder sdb = new SourceDestKeyBuilder();
- sdb.setSource(srcAddress.getIpPrefix());
- sdb.setDest(dstAddress.getIpPrefix());
+ sdb.setSource(srcAddress);
+ sdb.setDest(dstAddress);
return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
.setSourceDestKey(sdb.build()).build();
}
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
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.Ipv4Address;
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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AsNumberBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedNameBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
return addressFromIpAddress(address.getIpAddress());
} else if (address.getIpPrefix() != null) {
return addressFromIpPrefix(address.getIpPrefix());
+ } else if (address.getMacAddress() != null) {
+ return addressFromMacAddress(address.getMacAddress());
+ } else if (address.getDistinguishedNameType() != null) {
+ return addressFromDistinguishedName(address.getDistinguishedNameType());
+ } else if (address.getAsNumber() != null) {
+ return addressFromAsNumber(address.getAsNumber());
}
- // TODO the rest of the types
return null;
}
return null;
}
+ public static Address addressFromMacAddress(MacAddress address) {
+ if (address == null) {
+ return null;
+ } else {
+ return (Address) new MacBuilder().setMac(address).build();
+ }
+ }
+
+ public static Address addressFromDistinguishedName(DistinguishedNameType address) {
+ if (address == null) {
+ return null;
+ } else {
+ return (Address) new DistinguishedNameBuilder().setDistinguishedName(address).build();
+ }
+ }
+
+ public static Address addressFromAsNumber(AsNumber address) {
+ if (address == null) {
+ return null;
+ } else {
+ return (Address) new AsNumberBuilder().setAsNumber(address).build();
+ }
+ }
public static Rloc toRloc(SimpleAddress address) {
RlocBuilder builder = new RlocBuilder();
builder.setAddressType(addressTypeFromSimpleAddress(address));
return builder.build();
}
- public static Eid toEid(Eid eid, IpPrefix prefix) {
+ public static Eid toEid(Eid eid, SimpleAddress address) {
EidBuilder builder = new EidBuilder();
builder.setAddressType(eid.getAddressType());
builder.setVirtualNetworkId(eid.getVirtualNetworkId());
// XXX Not sure if the below actually works as expected... also, what happens to AFI?
- builder.setAddress(addressFromIpPrefix(prefix));
+ builder.setAddress(addressFromSimpleAddress(address));
return builder.build();
}
public static SourceDestKey asSrcDst(String src, String dst, int smask, int dmask) {
SourceDestKeyBuilder builder = new SourceDestKeyBuilder();
- builder.setSource(asIpPrefix(src, smask));
- builder.setDest(asIpPrefix(dst, dmask));
+ builder.setSource(new SimpleAddress(asIpPrefix(src, smask)));
+ builder.setDest(new SimpleAddress(asIpPrefix(dst, dmask)));
return builder.build();
}
if (!isSrcDst(addr)) {
return 0;
}
- return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getSource());
+ return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getSource());
}
public static short getDstMask(Eid eid) {
if (!isSrcDst(addr)) {
return 0;
}
- return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getDest());
+ return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getDest());
}
private static boolean isSrcDst(Address addr) {
"http://tools.ietf.org/html/draft-ietf-lisp-lcaf-10
#section-4.11";
leaf source {
- type inet:ip-prefix;
+ type simple-address;
description
- "Source prefix.";
+ "Source address.";
}
leaf dest {
- type inet:ip-prefix;
+ type simple-address;
description
- "Destination prefix.";
+ "Destination address.";
}
}
container key-value-address {
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
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.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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
assertEquals(SourceDestKeyLcaf.class, address.getAddressType());
SourceDestKey srcDestAddress = (SourceDestKey) address.getAddress();
- assertEquals((byte) 0x10, MaskUtil.getMaskForIpPrefix(srcDestAddress.getSourceDestKey().getSource()));
- assertEquals((byte) 0x18, MaskUtil.getMaskForIpPrefix(srcDestAddress.getSourceDestKey().getDest()));
+ assertEquals((byte) 0x10, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getSource()));
+ assertEquals((byte) 0x18, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getDest()));
assertEquals("17.34.51.68/16", String.valueOf(srcDestAddress.getSourceDestKey().getSource().getValue()));
assertEquals("34.51.68.85/24", String.valueOf(srcDestAddress.getSourceDestKey().getDest().getValue()));
@Test
public void serialize__Simple() throws Exception {
SourceDestKeyBuilder addressBuilder = new SourceDestKeyBuilder();
- addressBuilder.setSource(new IpPrefix(new Ipv4Prefix("17.34.51.68/8")));
- addressBuilder.setDest(new IpPrefix(new Ipv4Prefix("34.51.68.85/16")));
+ addressBuilder.setSource(new SimpleAddress(new IpPrefix(new Ipv4Prefix("17.34.51.68/8"))));
+ addressBuilder.setDest(new SimpleAddress(new IpPrefix(new Ipv4Prefix("34.51.68.85/16"))));
EidBuilder eb = new EidBuilder();
eb.setAddressType(SourceDestKeyLcaf.class);