use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method serialize__EidRecordFields.
@Test
public void serialize__EidRecordFields() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder eidToLocator1 = new MappingRecordBuilder();
eidToLocator1.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
eidToLocator1.setRecordTtl(7);
eidToLocator1.setAction(Action.SendMapRequest);
eidToLocator1.setAuthoritative(true);
eidToLocator1.setMapVersion((short) 3072);
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocator1.build()).build());
MappingRecordBuilder eidToLocator2 = new MappingRecordBuilder();
eidToLocator2.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.7/32"));
eidToLocator2.setRecordTtl(1000000);
eidToLocator2.setAction(Action.Drop);
eidToLocator2.setAuthoritative(false);
eidToLocator2.setMapVersion((short) 29);
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocator2.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
// First record
packet.position(12);
assertEquals(7, packet.getInt());
// skip Locator Count & Mask-len
packet.position(packet.position() + 2);
assertHexEquals((byte) 0x50, packet.get());
// skip Reserved byte
packet.position(packet.position() + 1);
assertEquals((short) 3072, packet.getShort());
// Second record
packet.position(packet.position() + 6);
assertEquals(1000000, packet.getInt());
// skip Locator Count & Mask-len
packet.position(packet.position() + 2);
assertHexEquals((byte) 0x60, packet.get());
// skip Reserved byte
packet.position(packet.position() + 1);
assertEquals((short) 29, packet.getShort());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder in project lispflowmapping by opendaylight.
the class MapNotifySerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapNotify deserialize(ByteBuffer notifyBuffer) {
try {
final byte typeAndFlags = notifyBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapNotify) {
throw new LispSerializationException("Expected Map-Notify packet (type 4), but was type " + type);
}
MapNotifyBuilder builder = new MapNotifyBuilder();
builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
builder.setXtrSiteIdPresent(xtrSiteIdPresent);
notifyBuffer.position(notifyBuffer.position() + Length.RES);
builder.setMergeEnabled(ByteUtil.extractBit(notifyBuffer.get(), Flags.MERGE_ENABLED));
byte recordCount = (byte) ByteUtil.getUnsignedByte(notifyBuffer);
builder.setNonce(notifyBuffer.getLong());
builder.setKeyId(notifyBuffer.getShort());
short authenticationLength = notifyBuffer.getShort();
byte[] authenticationData = new byte[authenticationLength];
notifyBuffer.get(authenticationData);
builder.setAuthenticationData(authenticationData);
if (xtrSiteIdPresent) {
List<MappingRecordBuilder> mrbs = new ArrayList<MappingRecordBuilder>();
for (int i = 0; i < recordCount; i++) {
mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(notifyBuffer));
}
byte[] xtrIdBuf = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
notifyBuffer.get(xtrIdBuf);
XtrId xtrId = new XtrId(xtrIdBuf);
byte[] siteIdBuf = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
notifyBuffer.get(siteIdBuf);
SiteId siteId = new SiteId(siteIdBuf);
builder.setXtrId(xtrId);
builder.setSiteId(siteId);
for (MappingRecordBuilder mrb : mrbs) {
mrb.setXtrId(xtrId);
mrb.setSiteId(siteId);
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mrb.build()).build());
}
} else {
for (int i = 0; i < recordCount; i++) {
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(notifyBuffer)).build());
}
}
notifyBuffer.limit(notifyBuffer.position());
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Notify (len=" + notifyBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder in project lispflowmapping by opendaylight.
the class MapRegisterSerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapRegister deserialize(ByteBuffer registerBuffer, InetAddress sourceRloc) {
try {
final byte typeAndFlags = registerBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapRegister) {
throw new LispSerializationException("Expected Map-Register packet (type 3), but was type " + type);
}
MapRegisterBuilder builder = new MapRegisterBuilder();
builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
builder.setProxyMapReply(ByteUtil.extractBit(typeAndFlags, Flags.PROXY));
builder.setXtrSiteIdPresent(xtrSiteIdPresent);
registerBuffer.position(registerBuffer.position() + Length.RES);
byte mergeAndMapReply = registerBuffer.get();
builder.setWantMapNotify(ByteUtil.extractBit(mergeAndMapReply, Flags.WANT_MAP_NOTIFY));
builder.setMergeEnabled(ByteUtil.extractBit(mergeAndMapReply, Flags.MERGE_ENABLED));
byte recordCount = (byte) ByteUtil.getUnsignedByte(registerBuffer);
builder.setNonce(registerBuffer.getLong());
builder.setKeyId(registerBuffer.getShort());
short authenticationLength = registerBuffer.getShort();
byte[] authenticationData = new byte[authenticationLength];
registerBuffer.get(authenticationData);
builder.setAuthenticationData(authenticationData);
if (xtrSiteIdPresent) {
List<MappingRecordBuilder> mrbs = new ArrayList<MappingRecordBuilder>();
for (int i = 0; i < recordCount; i++) {
mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(registerBuffer));
}
byte[] xtrIdBuf = new byte[Length.XTRID_SIZE];
registerBuffer.get(xtrIdBuf);
XtrId xtrId = new XtrId(xtrIdBuf);
byte[] siteIdBuf = new byte[Length.SITEID_SIZE];
registerBuffer.get(siteIdBuf);
SiteId siteId = new SiteId(siteIdBuf);
builder.setXtrId(xtrId);
builder.setSiteId(siteId);
for (MappingRecordBuilder mrb : mrbs) {
mrb.setXtrId(xtrId);
mrb.setSiteId(siteId);
mrb.setSourceRloc(LispAddressUtil.addressBinaryFromInet(sourceRloc));
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mrb.build()).build());
}
} else {
for (int i = 0; i < recordCount; i++) {
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(registerBuffer)).build());
}
}
registerBuffer.limit(registerBuffer.position());
byte[] mapRegisterBytes = new byte[registerBuffer.position()];
registerBuffer.position(0);
registerBuffer.get(mapRegisterBytes);
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder in project lispflowmapping by opendaylight.
the class LispSouthboundHandlerTest method lastMapNotifyPacket.
private DatagramPacket lastMapNotifyPacket() {
if (mapNotifyBuilder.getMappingRecordItem() == null) {
mapNotifyBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
}
mapNotifyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
mapNotifyBuilder.setNonce((long) 0);
mapNotifyBuilder.setKeyId((short) 0);
mapNotifyBuilder.setAuthenticationData(new byte[0]);
ByteBuffer serialize = MapNotifySerializer.getInstance().serialize(mapNotifyBuilder.build());
return new DatagramPacket(wrappedBuffer(serialize), new InetSocketAddress(0), new InetSocketAddress(0));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method registerAddress.
/*
// This registers an IP with a MapRegister, then adds a password via the
// northbound REST API
// and checks that the password works
public void testPasswordExactMatch() throws Exception {
cleanUP();
String ipString = "10.0.0.1";
LispIpv4Address address = LispAddressUtil.asIPAfiAddress(ipString);
int mask = 32;
String pass = "pass";
URL url = createPutURL("key");
String jsonAuthData = createAuthKeyJSON(pass, address, mask);
LOG.trace("Sending this JSON to LISP server: \n" + jsonAuthData);
LOG.trace("Address: " + address);
byte[] expectedSha = new byte[] { (byte) 146, (byte) 234, (byte) 52, (byte) 247, (byte) 186, (byte) 232,
(byte) 31, (byte) 249, (byte) 87,
(byte) 73, (byte) 234, (byte) 54, (byte) 225, (byte) 160, (byte) 129, (byte) 251, (byte) 73, (byte) 53,
(byte) 196, (byte) 62 };
byte[] zeros = new byte[20];
callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
// build a MapRegister
MapRegisterBuilder mapRegister = new MapRegisterBuilder();
mapRegister.setWantMapNotify(true);
mapRegister.setNonce((long) 8);
EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(address));
etlr.setMaskLength((short) mask);
etlr.setRecordTtl(254);
LocatorRecordBuilder record = new LocatorRecordBuilder();
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
etlr.getLocatorRecord().add(record.build());
mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
mapRegister.setAuthenticationData(zeros);
sendMapRegister(mapRegister.build());
assertNoPacketReceived(3000);
mapRegister.setAuthenticationData(expectedSha);
sendMapRegister(mapRegister.build());
assertMapNotifyReceived();
}
public void testPasswordMaskMatch() throws Exception {
cleanUP();
LispIpv4Address addressInRange = LispAddressUtil.asIPAfiAddress("10.20.30.40");
LispIpv4Address addressOutOfRange = LispAddressUtil.asIPAfiAddress("20.40.30.40");
LispIpv4Address range = LispAddressUtil.asIPAfiAddress("10.20.30.0");
int mask = 32;
String pass = "pass";
URL url = createPutURL("key");
String jsonAuthData = createAuthKeyJSON(pass, range, 8);
callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
// build a MapRegister
MapRegisterBuilder mapRegister = new MapRegisterBuilder();
mapRegister.setWantMapNotify(true);
mapRegister.setNonce((long) 8);
EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressInRange));
etlr.setMaskLength((short) mask);
etlr.setRecordTtl(254);
LocatorRecordBuilder record = new LocatorRecordBuilder();
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
etlr.getLocatorRecord().add(record.build());
mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
mapRegister
.setAuthenticationData(new byte[] { -15, -52, 38, -94, 125, -111, -68, -79, 68, 6, 101, 45, -1, 47, -4,
-67, -113, 104, -110, -71 });
sendMapRegister(mapRegister.build());
assertMapNotifyReceived();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressOutOfRange));
mapRegister
.setAuthenticationData(new byte[] { -54, 68, -58, -91, -23, 22, -88, -31, 113, 39, 115, 78, -68, -123,
-71, -14, -99, 67, -23, -73 });
sendMapRegister(mapRegister.build());
assertNoPacketReceived(3000);
}
*/
// takes an address, packs it in a MapRegister and sends it
private void registerAddress(Eid eid) throws SocketTimeoutException {
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
sleepForSeconds(1);
MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build();
sendMapRegister(mapRegister);
MapNotify mapNotify = receiveMapNotify();
assertEquals(8, mapNotify.getNonce().longValue());
}
Aggregations