use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest in project lispflowmapping by opendaylight.
the class MapRequestSerializationTest method deserialize__FlagsInSecondByte.
@Test
public void deserialize__FlagsInSecondByte() throws Exception {
MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 80 00 01 3d 8d " + "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " + "00 01 01 02 03 04"), null);
assertTrue(mr.isPitr());
assertFalse(mr.isSmrInvoked());
mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("19 40 00 01 3d 8d " + "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " + "00 01 01 02 03 04"), null);
assertFalse(mr.isPitr());
assertTrue(mr.isSmrInvoked());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest in project lispflowmapping by opendaylight.
the class MapRequestSerializationTest method deserialize__MultipleItrRlocs.
@Test
public void deserialize__MultipleItrRlocs() throws Exception {
MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("10 00 " + // This means 3 ITR - RLOCs
"02 " + "01 3d 8d 2a cd 39 c8 d6 08 00 00 " + // IPv4 (ITR-RLOC #1 of 3)
"00 01 c0 a8 88 0a " + // IPv6 (ITR-RLOC #2 of 3)
"00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 " + //
"00 01 11 22 34 56 " + // IPv4 (ITR-RLOC #3 of 3)
"00 20 00 01 01 02 03 04"), null);
assertEquals(3, mr.getItrRloc().size());
assertArrayEquals(new byte[] { (byte) 192, (byte) 168, (byte) 136, (byte) 10 }, ((Ipv4Binary) mr.getItrRloc().get(0).getRloc().getAddress()).getIpv4Binary().getValue());
assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, ((Ipv6Binary) mr.getItrRloc().get(1).getRloc().getAddress()).getIpv6Binary().getValue());
assertArrayEquals(new byte[] { 17, 34, 52, 86 }, ((Ipv4Binary) mr.getItrRloc().get(2).getRloc().getAddress()).getIpv4Binary().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest in project lispflowmapping by opendaylight.
the class MapResolver method handleMapRequest.
public void handleMapRequest(MapRequest request) {
LOG.trace("Map-Request received: {}", request);
// SMRs and RLOC probes are directed towards xTRs and we're a Map-Resolver here, so ignore them
if (request.isSmr() != null && request.isSmr()) {
LOG.debug("Map-Resolver ignoring incoming SMR control message.");
return;
}
if (request.isProbe() != null && request.isProbe()) {
LOG.debug("Map-Resolver ignoring incoming RLOC probe control message.");
return;
}
if (request.isSmrInvoked()) {
LOG.debug("SMR-invoked request received.");
LOG.trace("Map-Request object: {}", request);
for (EidItem eidItem : request.getEidItem()) {
final SmrEvent event = new SmrEvent(subscriberListFromItrRlocs(request.getItrRloc(), request.getSourceEid().getEid()), eidItem.getEid(), request.getNonce());
smrNotificationListener.onSmrInvokedReceived(event);
}
}
Eid srcEid = null;
if (request.getSourceEid() != null) {
srcEid = request.getSourceEid().getEid();
}
MapReplyBuilder replyBuilder = new MapReplyBuilder();
replyBuilder.setEchoNonceEnabled(false);
replyBuilder.setProbe(false);
replyBuilder.setSecurityEnabled(false);
replyBuilder.setNonce(request.getNonce());
replyBuilder.setMappingRecordItem(new ArrayList<>());
List<ItrRloc> itrRlocs = request.getItrRloc();
final IpAddressBinary sourceRloc = request.getSourceRloc();
for (EidItem eidRecord : request.getEidItem()) {
MappingData mappingData = mapService.getMapping(srcEid, eidRecord.getEid());
MappingRecord mapping;
if (mappingData == null) {
mapping = mapService.addNegativeMapping(eidRecord.getEid()).getRecord();
} else {
mapping = mappingData.getRecord();
}
if (itrRlocs != null && itrRlocs.size() != 0) {
if (subscriptionService && isValidSourceEidForSubscriber(srcEid)) {
final Rloc resolvedRloc = resolveRloc(itrRlocs, sourceRloc);
updateSubscribers(resolvedRloc, eidRecord.getEid(), mapping.getEid(), srcEid, mapping.getRecordTtl());
}
mapping = updateLocators(mapping, itrRlocs);
}
mapping = fixIfNotSDRequest(mapping, eidRecord.getEid());
mapping = fixTtlIfSmrInvoked(request, mapping);
replyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mapping).build());
}
requestHandler.handleMapReply(replyBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest in project lispflowmapping by opendaylight.
the class LispMappingServiceTest method handleMapRequestTest_NonProxy.
/**
* Tests {@link LispMappingService#handleMapRequest} method request from non-proxy xTR.
*/
@Test
public void handleMapRequestTest_NonProxy() {
final MapRequest mapRequest = Mockito.mock(MapRequest.class);
final Pair<MapRequest, TransportAddress> pair = getDefaultMapRequestPair();
final SendMapRequestInputBuilder smrib = new SendMapRequestInputBuilder().setMapRequest(pair.getLeft()).setTransportAddress(pair.getRight());
Mockito.when(mapRequest.getEidItem()).thenReturn(Lists.newArrayList(EID_ITEM_BUILDER.build()));
Mockito.when(tlsMapRequestMock.get()).thenReturn(pair);
assertNull(lispMappingService.handleMapRequest(mapRequest));
Mockito.verify(odlLispSbService).sendMapRequest(smrib.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest in project lispflowmapping by opendaylight.
the class MapResolverTest method isEqualIpVersionTest.
/**
* Tests {@link MapResolver#isEqualIpVersion} method.
*/
@Test
@Ignore
public void isEqualIpVersionTest() {
// input mapping
final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
Mockito.when(mapServiceMock.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock);
Mockito.when(subscriberSetMock.contains(Mockito.any(Subscriber.class))).thenReturn(false);
// ----------------------
// with sourceRloc = null
List<ItrRloc> itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv4BinaryAfi.class, IPV4_ADDRESS));
ArgumentCaptor<Subscriber> captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequestBuilder.setSourceRloc(null).setItrRloc(itrRlocList).build());
Mockito.verify(subscriberSetMock).add(captor.capture());
// Since mapRequest's sourceRloc is null, first ItrRloc from the itrRlocList must be used.
assertEquals(MacAfi.class, captor.getValue().getSrcRloc().getAddressType());
// ----------------------
// with sourceRloc address = itrRloc address
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv4BinaryAfi.class, IPV4_ADDRESS));
MapRequest mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_1).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(2)).add(captor.capture());
assertEquals(IPV4_ADDRESS, captor.getValue().getSrcRloc().getAddress());
// ----------------------
// with sourceRloc address Afi = itrRloc address Afi (for Ipv4)
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv6Afi.class, IPV6_ADDRESS), newItrRloc(Ipv4Afi.class, IPV4_ADDRESS));
mapRequest = mapRequestBuilder.setSourceRloc(IPV6_ADDRESS_BINARY).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(3)).add(captor.capture());
assertEquals(IPV6_ADDRESS, captor.getValue().getSrcRloc().getAddress());
// ----------------------
// with sourceRloc address Afi = itrRloc address Afi (for Ipv6)
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv6Afi.class, IPV6_ADDRESS), newItrRloc(Ipv4Afi.class, IPV4_ADDRESS));
mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_2).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(4)).add(captor.capture());
assertEquals(IPV4_ADDRESS, captor.getValue().getSrcRloc().getAddress());
// ----------------------
// with no common ip address nor Afi
final Mac mac = new MacBuilder().setMac(new MacAddress("aa:bb:cc:dd:ee:ff")).build();
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, mac), newItrRloc(NoAddressAfi.class, Mockito.mock(NoAddress.class)));
mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_1).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(5)).add(captor.capture());
assertEquals(mac, captor.getValue().getSrcRloc().getAddress());
}
Aggregations