use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method serialize__LocatorRecordFields.
@Test
public void serialize__LocatorRecordFields() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder eidToLocatorBuilder = new MappingRecordBuilder();
eidToLocatorBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
eidToLocatorBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
LocatorRecordBuilder locatorBuilder1 = new LocatorRecordBuilder();
locatorBuilder1.setPriority((short) 0xF3);
locatorBuilder1.setWeight((short) 0xF6);
locatorBuilder1.setMulticastPriority((short) 0xA3);
locatorBuilder1.setMulticastWeight((short) 0x06);
locatorBuilder1.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.1"));
locatorBuilder1.setLocalLocator(true);
locatorBuilder1.setRlocProbed(true);
locatorBuilder1.setRouted(true);
eidToLocatorBuilder.getLocatorRecord().add(locatorBuilder1.build());
LocatorRecordBuilder locatorBuilder2 = new LocatorRecordBuilder();
locatorBuilder2.setPriority((short) 0x03);
locatorBuilder2.setWeight((short) 0x06);
locatorBuilder2.setMulticastPriority((short) 0x03);
locatorBuilder2.setMulticastWeight((short) 0xF1);
locatorBuilder2.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.2"));
locatorBuilder2.setLocalLocator(false);
locatorBuilder2.setRlocProbed(false);
locatorBuilder2.setRouted(false);
eidToLocatorBuilder.getLocatorRecord().add(locatorBuilder2.build());
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocatorBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
// First locator record
packet.position(12 + 16);
assertHexEquals((byte) 0xF3, packet.get());
assertHexEquals((byte) 0xF6, packet.get());
assertHexEquals((byte) 0xA3, packet.get());
assertHexEquals((byte) 0x06, packet.get());
packet.position(packet.position() + 1);
assertHexEquals((byte) 0x07, packet.get());
// Second locator record
packet.position(packet.position() + 6);
assertHexEquals((byte) 0x03, packet.get());
assertHexEquals((byte) 0x06, packet.get());
assertHexEquals((byte) 0x03, packet.get());
assertHexEquals((byte) 0xF1, packet.get());
packet.position(packet.position() + 1);
assertHexEquals((byte) 0x00, packet.get());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MapRequestSerializationTest method serialize__AllWithMapReply.
@Test
public void serialize__AllWithMapReply() throws Exception {
MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
mapRequestBuilder.setProbe(true);
mapRequestBuilder.setMapDataPresent(true);
mapRequestBuilder.setPitr(true);
mapRequestBuilder.setNonce((long) 13);
mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(("10.0.0.1"))).build());
mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("1.2.3.4")).build());
mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv6Rloc("1:2:3:4:5:6:7:8")).build());
mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32")).build());
MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/0"));
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
LocatorRecordBuilder locatorBuilder = new LocatorRecordBuilder();
locatorBuilder.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.2"));
recordBuilder.getLocatorRecord().add(locatorBuilder.build());
MapReplyBuilder mapreplyBuilder = new MapReplyBuilder();
mapreplyBuilder.setMappingRecord(recordBuilder.build());
mapRequestBuilder.setMapReply(mapreplyBuilder.build());
ByteBuffer expected = hexToByteBuffer("16 80 01 01 00 00 " + "00 00 00 00 00 0D 00 01 0a 00 00 01 00 01 01 02 03 04 00 02 00 01 00 02 00 03 00 04 00 05 00 06 " + // map
"00 07 00 08 00 20 00 01 01 02 03 04 " + "00 00 00 00 01 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 02");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mapRequestBuilder.build()).array());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class LispAuthenticationTest method authenticate__MapNotifyNoAuthenticationData.
// @Test
// public void authenticate__MapNotifySHA1() throws Exception {
// MapNotify mapNotify = new MapNotify();
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(1)));
//
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(73)));
// mapNotify.setNonce(6161616161L);
// mapNotify.setKeyId((short) 0x0001);
// byte[] wantedAuthenticationData = new byte[] { (byte) 0x66, (byte) 0x69,
// (byte) 0x2c, (byte) 0xb8, (byte) 0xb8, (byte) 0x58, (byte) 0x7c,
// (byte) 0x8f, (byte) 0x4c, (byte) 0xd4, (byte) 0x8b, (byte) 0x77, (byte)
// 0x46, (byte) 0xf0, (byte) 0x6b, (byte) 0x9f, (byte) 0x66,
// (byte) 0xd2, (byte) 0xaa, (byte) 0x2c };
// ArrayAssert.assertEquals(wantedAuthenticationData,
// LispAuthenticationUtil.createAuthenticationData(mapNotify, "password"));
//
// }
//
// @Test
// public void authenticate__MapNotifySHA256() throws Exception {
// MapNotify mapNotify = new MapNotify();
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(1)));
//
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(73)));
// mapNotify.setNonce(6161616161L);
// mapNotify.setKeyId((short) 0x0002);
// byte[] wantedAuthenticationData = new byte[] { (byte) 0x4c, (byte) 0xf1,
// (byte) 0x5a, (byte) 0x4c, (byte) 0xdb, (byte) 0x8d, (byte) 0x88,
// (byte) 0x47, (byte) 0xf1, (byte) 0x7f, (byte) 0x27, (byte) 0x81, (byte)
// 0x1e, (byte) 0xbf, (byte) 0x22, (byte) 0xc7, (byte) 0xe6,
// (byte) 0x70, (byte) 0x16, (byte) 0x5e, (byte) 0xa1, (byte) 0x59, (byte)
// 0xe4, (byte) 0x06, (byte) 0x3f, (byte) 0xc2, (byte) 0x6a,
// (byte) 0x1c, (byte) 0x86, (byte) 0xa5, (byte) 0x8d, (byte) 0x63 };
// ArrayAssert.assertEquals(wantedAuthenticationData,
// LispAuthenticationUtil.createAuthenticationData(mapNotify, "password"));
//
// }
@Test
public void authenticate__MapNotifyNoAuthenticationData() throws Exception {
MapNotifyBuilder mapNotifyBuilder = new MapNotifyBuilder();
mapNotifyBuilder.setKeyId((short) 0x0000);
mapNotifyBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
etlrBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("1.1.1.1/32"));
etlrBuilder.setRecordTtl(55);
mapNotifyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
final ByteBuffer serializedMapNotifyMsg = MapNotifySerializer.getInstance().serialize(mapNotifyBuilder.build());
ArrayAssert.assertEquals(new byte[0], LispAuthenticationUtil.createAuthenticationData(serializedMapNotifyMsg, "password"));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MappingSystem method updateServicePathMappingRecord.
private MappingData updateServicePathMappingRecord(MappingData mappingData, Eid eid) {
// keep properties of original record
MappingRecordBuilder recordBuilder = new MappingRecordBuilder(mappingData.getRecord());
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
// there should only be one locator record
if (mappingData.getRecord().getLocatorRecord().size() != 1) {
LOG.warn("MappingRecord associated to ServicePath EID has more than one locator!");
return mappingData;
}
LocatorRecord locatorRecord = mappingData.getRecord().getLocatorRecord().get(0);
long serviceIndex = ((ServicePath) eid.getAddress()).getServicePath().getServiceIndex();
int index = LispAddressUtil.STARTING_SERVICE_INDEX - (int) serviceIndex;
Rloc rloc = locatorRecord.getRloc();
if (rloc.getAddress() instanceof Ipv4 || rloc.getAddress() instanceof Ipv6) {
if (index != 0) {
LOG.warn("Service Index should be 255 for simple IP RLOCs!");
}
return mappingData;
} else if (rloc.getAddress() instanceof ExplicitLocatorPath) {
ExplicitLocatorPath elp = (ExplicitLocatorPath) rloc.getAddress();
List<Hop> hops = elp.getExplicitLocatorPath().getHop();
if (index < 0 || index > hops.size()) {
LOG.warn("Service Index out of bounds!");
return mappingData;
}
SimpleAddress nextHop = hops.get(index).getAddress();
LocatorRecordBuilder lrb = new LocatorRecordBuilder(locatorRecord);
lrb.setRloc(LispAddressUtil.toRloc(nextHop));
recordBuilder.getLocatorRecord().add(lrb.build());
return new MappingData(recordBuilder.build());
} else {
LOG.warn("Nothing to do with ServicePath mapping record");
return mappingData;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MappingSystem method buildNegativeMapping.
private MappingRecord buildNegativeMapping(Eid eid) {
MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
recordBuilder.setAuthoritative(false);
recordBuilder.setMapVersion((short) 0);
recordBuilder.setEid(eid);
if (eid.getAddressType().equals(Ipv4PrefixBinaryAfi.class) || eid.getAddressType().equals(Ipv6PrefixBinaryAfi.class)) {
Eid widestNegativePrefix = getWidestNegativePrefix(eid);
if (widestNegativePrefix != null) {
recordBuilder.setEid(widestNegativePrefix);
}
}
recordBuilder.setAction(LispMessage.NEGATIVE_MAPPING_ACTION);
// if (getAuthenticationKey(eid) != null) {
// recordBuilder.setRecordTtl(TTL_RLOC_TIMED_OUT);
// } else {
recordBuilder.setRecordTtl(TTL_NO_RLOC_KNOWN);
// }
return recordBuilder.build();
}
Aggregations