use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method queryForAddress.
private MapReply queryForAddress(Eid eid, String srcEid) throws SocketTimeoutException {
MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
mapRequestBuilder.setNonce((long) 4);
mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
if (srcEid != null) {
mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(srcEid)).build());
} else {
mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
}
mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
mapRequestBuilder.setAuthoritative(false);
mapRequestBuilder.setMapDataPresent(false);
mapRequestBuilder.setPitr(false);
mapRequestBuilder.setProbe(false);
mapRequestBuilder.setSmr(false);
mapRequestBuilder.setSmrInvoked(false);
sendMapRequest(mapRequestBuilder.build());
return receiveMapReply();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest__withSubscribersToRemove.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
@Ignore
public void handleMapRequest__withSubscribersToRemove() {
// input mapping
final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
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);
Subscriber subscriberMock = new Subscriber(mapRequestBuilder.getItrRloc().get(0).getRloc(), mapRequestBuilder.getSourceEid().getEid(), Subscriber.DEFAULT_SUBSCRIBER_TIMEOUT);
subscriberMock.setSubscriberTtlByRecordTtl(mappingRecordBuilder.getRecordTtl());
Mockito.when(subscriberSetMock.contains(subscriberMock)).thenReturn(true);
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
// check if a subscriber is re-instantiating when there already is one in the subscriber set
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(subscriberSetMock).remove(subscriberMock);
Mockito.verify(subscriberSetMock).add(subscriberMock);
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
Mockito.verify(mapServiceMock).addData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS, subscriberSetMock);
// verify that itrRloc is subscribed to dst address
mappingRecordBuilder.setEid(SOURCE_DEST_KEY_EID);
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(IPV4_PREFIX_EID_2).build());
mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_2)).thenReturn(mappingData);
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(mapServiceMock).getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc in project lispflowmapping by opendaylight.
the class MapResolver method updateLocators.
// Process locators according to configured policy
private MappingRecord updateLocators(MappingRecord mapping, List<ItrRloc> itrRlocs) {
// no fixing if elpPolicy is default
if (elpPolicy.equalsIgnoreCase("default")) {
return mapping;
}
List<LocatorRecord> locatorRecords = mapping.getLocatorRecord();
// if no updated is needed, just return the mapping
if (!locatorsNeedFixing(locatorRecords)) {
return mapping;
}
MappingRecordBuilder recordBuilder = new MappingRecordBuilder(mapping);
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
try {
for (LocatorRecord record : locatorRecords) {
Rloc container = record.getRloc();
// done
if ((!(container.getAddress() instanceof ExplicitLocatorPath)) || elpPolicy.equalsIgnoreCase("default") || itrRlocs == null) {
recordBuilder.getLocatorRecord().add(new LocatorRecordBuilder().setLocalLocator(record.isLocalLocator()).setRlocProbed(record.isRlocProbed()).setWeight(record.getWeight()).setPriority(record.getPriority()).setMulticastWeight(record.getMulticastWeight()).setMulticastPriority(record.getMulticastPriority()).setRouted(record.isRouted()).setRloc(container).setLocatorId(record.getLocatorId()).build());
continue;
}
ExplicitLocatorPath teAddress = ((ExplicitLocatorPath) container.getAddress());
SimpleAddress nextHop = getNextELPHop(teAddress, itrRlocs);
if (nextHop != null) {
java.lang.Short priority = record.getPriority();
if (elpPolicy.equalsIgnoreCase("both")) {
recordBuilder.getLocatorRecord().add(new LocatorRecordBuilder().setLocalLocator(record.isLocalLocator()).setRlocProbed(record.isRlocProbed()).setWeight(record.getWeight()).setPriority(record.getPriority()).setMulticastWeight(record.getMulticastWeight()).setMulticastPriority(record.getMulticastPriority()).setRouted(record.isRouted()).setRloc(container).setLocatorId(record.getLocatorId()).build());
// XXX Complex cases like several ELPs with different priorities are not handled
if (priority != 254 || priority != 255) {
priority++;
}
}
// Build and add the simple RLOC
recordBuilder.getLocatorRecord().add(new LocatorRecordBuilder().setLocalLocator(record.isLocalLocator()).setRlocProbed(record.isRlocProbed()).setWeight(record.getWeight()).setPriority(priority).setMulticastWeight(record.getMulticastWeight()).setMulticastPriority(record.getMulticastPriority()).setRouted(record.isRouted()).setRloc(LispAddressUtil.toRloc(nextHop)).setLocatorId(record.getLocatorId()).build());
}
}
} catch (ClassCastException cce) {
LOG.error("Class Cast Exception while building EidToLocatorRecord: {}", ExceptionUtils.getStackTrace(cce));
}
return recordBuilder.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 resolveRloc.
private Rloc resolveRloc(List<ItrRloc> itrRlocList, IpAddressBinary srcRloc) {
if (srcRloc == null) {
return itrRlocList.get(0).getRloc();
}
byte[] srcRlocByte;
if (srcRloc.getIpv4AddressBinary() != null) {
srcRlocByte = srcRloc.getIpv4AddressBinary().getValue();
} else {
srcRlocByte = srcRloc.getIpv6AddressBinary().getValue();
}
Rloc equalIpvRloc = null;
for (ItrRloc itrRloc : itrRlocList) {
final Rloc rloc = itrRloc.getRloc();
final byte[] itrRlocByte = LispAddressUtil.ipAddressToByteArray(rloc.getAddress());
// return an Rloc equal to the source Rloc
if (itrRlocByte != null && LispAddressUtil.compareIpAddressByteArrays(srcRlocByte, itrRlocByte) == 0) {
return rloc;
}
// else lookup the first Rloc with identical Ip version
if (equalIpvRloc == null && isEqualIpVersion(srcRloc, rloc)) {
equalIpvRloc = rloc;
}
}
if (equalIpvRloc != null) {
return equalIpvRloc;
} else {
// if none of the above, return the first Rloc
return itrRlocList.get(0).getRloc();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc in project lispflowmapping by opendaylight.
the class MapResolver method updateSubscribers.
private void updateSubscribers(Rloc itrRloc, Eid reqEid, Eid mapEid, Eid srcEid, Integer recordTtl) {
Subscriber subscriber = new Subscriber(itrRloc, srcEid, Subscriber.recordTtlToSubscriberTime(recordTtl));
Eid subscribedEid = mapEid;
// mapping will be pushed to dst as well (see sendSMRs in MapServer)
if (mapEid.getAddressType().equals(SourceDestKeyLcaf.class) && !reqEid.getAddressType().equals(SourceDestKeyLcaf.class)) {
subscribedEid = SourceDestKeyHelper.getDstBinary(mapEid);
}
mapService.subscribe(subscriber, subscribedEid);
}
Aggregations