@Test
public void testSmr() throws Exception {
registerQueryRegisterWithSmr();
- testRepeatedSmr();
+ //testRepeatedSmr();
}
@Test
}
@Test
- public void testNegativePrefix_gapIntersection() throws UnknownHostException {
+ public void testNbAndSbNegativePrefix() throws UnknownHostException {
insertMappings();
testGapIntersection();
insertMappings();
testMultipleMappings();
+ }
+ @Test
+ public void testExplicitSbNegativePrefixes() {
// https://bugs.opendaylight.org/show_bug.cgi?id=8679
testNegativePrefix();
+
+ // https://bugs.opendaylight.org/show_bug.cgi?id=9023
+ testPositiveMappingRemoval();
+
+ // https://bugs.opendaylight.org/show_bug.cgi?id=9037
+ testPositivePrefixOverlappingNegativePrefix();
}
private void testRepeatedSmr() throws SocketTimeoutException, UnknownHostException {
final List<MapRequest> requests = Lists.newArrayList();
byte[][] buffers = reader.getBuffers(expectedSmrs);
for (byte[] buf : buffers) {
- MapRequest request = MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(buf), inetAddress);
- requests.add(request);
+ ByteBuffer packet = ByteBuffer.wrap(buf);
+ if (checkType(packet, MessageType.MapRequest)) {
+ MapRequest request = MapRequestSerializer.getInstance().deserialize(packet, inetAddress);
+ requests.add(request);
+ }
}
return requests;
}
assertTrue(MappingRecordUtil.isNegativeMapping(mr));
}
+ private void testPositiveMappingRemoval() {
+ cleanUP();
+
+ insertNBMappings(1L, "192.167.0.0/16", "192.169.0.0/16");
+ insertSBMappings(1L, "192.168.32.0/19");
+
+ MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32"));
+ Eid expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/19");
+ MappingRecord mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
+ assertEquals(expectedNegativePrefix, mr.getEid());
+ assertTrue(MappingRecordUtil.isNegativeMapping(mr));
+
+ mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.64.1/32"));
+ expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.64.0/18");
+ mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
+ assertEquals(expectedNegativePrefix, mr.getEid());
+ assertTrue(MappingRecordUtil.isNegativeMapping(mr));
+
+ mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.128.1/32"));
+ expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.128.0/17");
+ mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
+ assertEquals(expectedNegativePrefix, mr.getEid());
+ assertTrue(MappingRecordUtil.isNegativeMapping(mr));
+
+ printMapCacheState();
+
+ mapService.removeMapping(MappingOrigin.Southbound, LispAddressUtil.asIpv4PrefixBinaryEid(
+ 1L, "192.168.32.0/19"));
+
+ printMapCacheState();
+
+ mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.32.1/32"));
+ expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/16");
+ mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
+ assertEquals(expectedNegativePrefix, mr.getEid());
+ assertTrue(MappingRecordUtil.isNegativeMapping(mr));
+
+ printMapCacheState();
+ }
+
+ private void testPositivePrefixOverlappingNegativePrefix() {
+ cleanUP();
+
+ insertNBMappings(1L, "192.167.0.0/16", "192.169.0.0/16");
+
+ MapReply mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32"));
+ Eid expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/16");
+ MappingRecord mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
+ assertEquals(expectedNegativePrefix, mr.getEid());
+ assertTrue(MappingRecordUtil.isNegativeMapping(mr));
+
+ insertNBMappings(1L, "192.168.1.0/24");
+
+ mapReply = lms.handleMapRequest(newMapRequest(1L, "192.168.0.1/32"));
+ expectedNegativePrefix = LispAddressUtil.asIpv4PrefixBinaryEid(1L, "192.168.0.0/24");
+ mr = mapReply.getMappingRecordItem().get(0).getMappingRecord();
+ assertEquals(expectedNegativePrefix, mr.getEid());
+ assertTrue(MappingRecordUtil.isNegativeMapping(mr));
+ }
+
private void insertMappings() {
cleanUP();
mapService.setLookupPolicy(IMappingService.LookupPolicy.NB_AND_SB);
}
private void insertNBMappings(long iid, String ... prefixes) {
+ LOG.debug("Adding Northbound mappings for prefixes: {}", prefixes);
final InstanceIdType iiType = new InstanceIdType(iid);
for (String prefix : prefixes) {
MappingRecord record = newMappingRecord(prefix, iiType);
mapService.addMapping(MappingOrigin.Northbound, record.getEid(), null, new MappingData(record));
}
+ sleepForMilliseconds(25);
+ printMapCacheState();
}
private void insertSBMappings(long iid, String ... prefixes) {
+ LOG.debug("Adding Southbound mappings for prefixes: {}", prefixes);
final InstanceIdType iiType = new InstanceIdType(iid);
Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", iiType);
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
mapService.addMapping(MappingOrigin.Southbound, record.getEid(), null,
new MappingData(record, System.currentTimeMillis()));
}
+ printMapCacheState();
+ }
+
+ private void printMapCacheState() {
+ LOG.debug("Map-cache state:\n{}", mapService.prettyPrintMappings());
}
/**
.setLocatorRecord(Lists.newArrayList(new LocatorRecordBuilder()
.setRloc(LispAddressUtil.asIpv4Rloc("2.2.2.2"))
.setLocatorId("loc_id")
+ .setRouted(true)
.setPriority((short) 1)
.setWeight((short) 1).build()))
.setTimestamp(System.currentTimeMillis())
mapRegisterBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
mapRegisterBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
etlrBuilder.build()).build());
- sendMapRegister(mapRegisterBuilder.build());
+ MapRegister mapRegister = mapRegisterBuilder.build();
+ LOG.trace("Sending Map-Register via socket: {}", mapRegister);
+ sendMapRegister(mapRegister);
MapNotify mapNotify = receiveMapNotify();
+ LOG.trace("Received Map-Notify via socket: {}", mapNotify);
assertEquals(8, mapNotify.getNonce().longValue());
// wait for the notifications to propagate
sleepForSeconds(1);
}
private MapRequest receiveMapRequest(DatagramSocket datagramSocket) throws SocketTimeoutException {
- return MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket(
- datagramSocket, 30000).getData()), null);
+ ByteBuffer packet = ByteBuffer.wrap(receivePacket(datagramSocket, 30000).getData());
+ while (!checkType(packet, MessageType.MapRequest)) {
+ packet = ByteBuffer.wrap(receivePacket(datagramSocket, 30000).getData());
+ }
+ return MapRequestSerializer.getInstance().deserialize(packet, null);
}
private MapNotify receiveMapNotify() throws SocketTimeoutException {
- return MapNotifySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
+ ByteBuffer packet = ByteBuffer.wrap(receivePacket().getData());
+ while (!checkType(packet, MessageType.MapNotify)) {
+ packet = ByteBuffer.wrap(receivePacket().getData());
+ }
+ return MapNotifySerializer.getInstance().deserialize(packet);
+ }
+
+ private static boolean checkType(ByteBuffer packet, MessageType type) {
+ final int receivedType = ByteUtil.getUnsignedByte(packet, LispMessage.Pos.TYPE) >> 4;
+ return MessageType.forValue(receivedType) == type;
}
private void sendMapRequest(MapRequest mapRequest) {