+ "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 " //
+ "b0 21 27 a8 21 41 04 f3 46 5a 5a 5b 5c 5d 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertFalse(LispAuthenticationUtil.validate(mapRegister, "password"));
}
MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
+ "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
hexToByteBuffer("38 00 01 01 FF BB " //
+ "00 00 00 00 00 00 00 02 00 20 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+ "00 00 00 00 00 00 00 00 00 00 " //
+ "00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
assertTrue(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+ "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
+ "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
mappingEntriesSaver = new ValueSaverAction<MappingEntry<?>[]>();
}
*/
package org.opendaylight.lispflowmapping.lisp.serializer;
+import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.IpAddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.IpAddressBinaryBuilder;
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.MessageType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
return registerBuffer;
}
- public MapRegister deserialize(ByteBuffer registerBuffer) {
+ public MapRegister deserialize(ByteBuffer registerBuffer, InetAddress sourceRloc) {
try {
MapRegisterBuilder builder = new MapRegisterBuilder();
builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
for (MappingRecordBuilder mrb : mrbs) {
mrb.setXtrId(xtrId);
mrb.setSiteId(siteId);
+ mrb.setSourceRloc(getSourceRloc(sourceRloc));
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
mrb.build()).build());
}
}
+ private static IpAddressBinary getSourceRloc(InetAddress sourceRloc) {
+ byte[] srcRloc;
+ if (sourceRloc == null) {
+ srcRloc = InetAddress.getLoopbackAddress().getAddress();
+ } else {
+ srcRloc = sourceRloc.getAddress();
+ }
+
+ return IpAddressBinaryBuilder.getDefaultInstance(srcRloc);
+ }
+
private interface Flags {
byte PROXY = 0x08;
byte XTRSITEID = 0x02;
return deserializeToBuilder(buffer).build();
}
- public MappingRecordBuilder deserializeToBuilder(ByteBuffer buffer) {
+ public MappingRecordBuilder deserializeToBuilder(ByteBuffer buffer) {
MappingRecordBuilder builder = new MappingRecordBuilder();
builder.setRecordTtl(buffer.getInt());
byte locatorCount = (byte) ByteUtil.getUnsignedByte(buffer);
--- /dev/null
+package org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105;
+
+
+/**
+ * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
+ * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
+ *
+ * The reason behind putting it under src/main/java is:
+ * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
+ * loss of user code.
+ *
+ */
+public class IpAddressBinaryBuilder {
+
+ public static IpAddressBinary getDefaultInstance(java.lang.String defaultValue) {
+ return new IpAddressBinary(Ipv4AddressBinary.getDefaultInstance(defaultValue));
+ }
+
+ public static IpAddressBinary getDefaultInstance(byte[] defaultValue) {
+ if (defaultValue.length == 4) {
+ return new IpAddressBinary(new Ipv4AddressBinary(defaultValue));
+ } else if (defaultValue.length == 16) {
+ return new IpAddressBinary(new Ipv6AddressBinary(defaultValue));
+ }
+ return null;
+ }
+
+}
reference "https://tools.ietf.org/html/rfc6830";
}
+ typedef ipv4-address-binary {
+ type binary {
+ length "4";
+ }
+ description
+ "The ipv4-address-binary type represents an IPv4 address in binary
+ in network byte order.";
+ }
+
+ typedef ipv6-address-binary {
+ type binary {
+ length "16";
+ }
+ description
+ "The ipv6-address-binary type represents an IPv6 address in binary
+ in network byte order.";
+ }
+
+ typedef ip-address-binary {
+ type union {
+ type ipv4-address-binary;
+ type ipv6-address-binary;
+ }
+ description
+ "The ip-address-binary type represents an IP address in binary
+ in network byte order, and is IP version neutral. The length of
+ the byte array implies the IP version.";
+ }
+
grouping transport-address {
container transport-address {
leaf ipAddress {
}
}
+ grouping mapping-record-metadata {
+ leaf xtr-id {
+ type binary {
+ length "16";
+ }
+ description
+ "128 bit xTR identifier.";
+ }
+ leaf site-id {
+ type binary {
+ length "8";
+ }
+ description
+ "64 bit site identifier.";
+ }
+ leaf source-rloc {
+ type ip-address-binary;
+ description
+ "The Source IP address used for sending the enclosing control
+ packet in RLOC space.";
+ }
+ leaf timestamp {
+ type int64;
+ description
+ "Milliseconds since January 1, 1970, 00:00:00 GMT";
+ }
+ description
+ "This is a collection of fields which are not present in the actual
+ mapping record defined in RFC 6830, but are used internally in
+ OpenDaylight";
+ }
+
grouping mapping-record-container {
container mapping-record {
leaf recordTtl {
// locator record list
uses LocatorRecords;
- leaf xtr-id {
- description "128 bit xTR identifier";
- type binary {
- length "16";
- }
- }
-
- leaf site-id {
- description "64 bit site identifier";
- type binary {
- length "8";
- }
- }
-
- leaf timestamp {
- description "Milliseconds since January 1, 1970, 00:00:00 GMT";
- type int64;
- }
+ // metadata
+ uses mapping-record-metadata;
}
}
ArrayAssert.assertEquals(
MapRegisterSerializer.getInstance().serialize(mapRegister).array(),
MapRegisterSerializer.getInstance()
- .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance().serialize(mapRegister)))
+ .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance().serialize(mapRegister), null))
.array());
}
//
+ "00 00 00 00 00 00 00 00 00 00 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertTrue(mr.isProxyMapReply());
assertTrue(mr.isWantMapNotify());
+ "00 00 00 01 00 01 c3 a8 c8 01 0a 32 ff 00 00 04 "
+ "00 01 ac 10 01 02 15 1a 39 80 e3 35 e6 c4 49 a6 "
+ "90 87 20 65 9a b7 00 00 00 00 00 00 00 00 ");
- MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb);
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb, null);
assertTrue(mr.isXtrSiteIdPresent());
+ "00 00 00 0a 01 20 10 00 00 00 00 01 96 10 fe 01 01 64 " // Record
// 4
+ "ff 00 00 05 00 01 c0 a8 88 0d " // contd
- ));
+ ), null);
assertEquals(4, mr.getMappingRecordItem().size());
assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), mr.getMappingRecordItem().get(0)
+ "60 11 34 A4 " // priorities + weights
+ "00 03 " // Flags
+ "00 01 c0 a8 88 0a " // Locator
- ));
+ ), null);
assertEquals(1, mr.getMappingRecordItem().size());
MappingRecordItem eidToLocator = mr.getMappingRecordItem().get(0);
+ "00 00 00 0d 01 20 20 00 03 33 00 01 96 10 fe 01 01 64 " // Record
// 3
+ "ff 00 00 05 00 01 c0 a8 88 0d " // contd
- ));
+ ), null);
assertEquals(4, mr.getMappingRecordItem().size());
+ "00 00 00 00 00 00 00 01 00 14 ec 47 1e 53 25 91 " //
+ "2f 68 10 75 13 dd 2c e8 6e 3c ac 94 ed e4 00 00 " //
+ "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertEquals(1, mr.getMappingRecordItem().size());
assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
+ "00 00 00 00 00 00 00 00 00 14 e8 f5 0b c5 c5 f2 " //
+ "b0 21 27 a8 21 a5 68 89 ec 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
}
@Test
+ "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
+ "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertTrue(mr.isProxyMapReply());
assertTrue(mr.isWantMapNotify());
//
+ "11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertTrue(mr.isProxyMapReply());
assertTrue(mr.isWantMapNotify());
private void handleMapRegister(ByteBuffer inBuffer, InetAddress sourceAddress, int port) {
try {
- MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer);
+ MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer, sourceAddress);
AddMappingBuilder addMappingBuilder = new AddMappingBuilder();
addMappingBuilder.setMapRegister(LispNotificationHelper.convertMapRegister(mapRegister));
TransportAddressBuilder transportAddressBuilder = new TransportAddressBuilder();