use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc 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.maprequest.ItrRloc in project lispflowmapping by opendaylight.
the class MapResolver method getNextELPHop.
private SimpleAddress getNextELPHop(ExplicitLocatorPath elp, List<ItrRloc> itrRlocs) {
SimpleAddress nextHop = null;
List<Hop> hops = elp.getExplicitLocatorPath().getHop();
if (hops != null && hops.size() > 0) {
// By default we return the first hop
nextHop = hops.get(0).getAddress();
for (Hop hop : hops) {
Address hopAddress = LispAddressUtil.addressFromSimpleAddress(hop.getAddress());
for (ItrRloc itrRloc : itrRlocs) {
if (itrRloc.getRloc().getAddress().equals(hopAddress)) {
int iterator = hops.indexOf(hop);
if (iterator < hops.size() - 1) {
nextHop = hops.get(iterator + 1).getAddress();
return nextHop;
}
}
}
}
}
return nextHop;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc in project lispflowmapping by opendaylight.
the class MapResolverTest method getDefaultItrRlocList.
private static List<ItrRloc> getDefaultItrRlocList() {
final List<ItrRloc> itrRlocList = new ArrayList<>();
final ItrRloc itrRloc = new ItrRlocBuilder().setKey(new ItrRlocKey(ITR_RLOC_KEY_STRING)).setItrRlocId(ITR_RLOC_ID_STRING).setRloc(RLOC_1).build();
itrRlocList.add(itrRloc);
return itrRlocList;
}
Aggregations