use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MappingDataListener method convertToBinaryIfNecessary.
private static List<LocatorRecord> convertToBinaryIfNecessary(List<LocatorRecord> originalLocators) {
List<LocatorRecord> convertedLocators = null;
for (LocatorRecord record : originalLocators) {
if (LispAddressUtil.addressNeedsConversionToBinary(record.getRloc().getAddress())) {
LocatorRecordBuilder lrb = new LocatorRecordBuilder(record);
lrb.setRloc(LispAddressUtil.convertToBinary(record.getRloc()));
if (convertedLocators == null) {
convertedLocators = new ArrayList<LocatorRecord>();
}
convertedLocators.add(lrb.build());
}
}
if (convertedLocators != null) {
return convertedLocators;
}
return originalLocators;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder 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.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest_withBothPolicy.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
public void handleMapRequest_withBothPolicy() {
mapResolver = new MapResolver(mapServiceMock, true, "both", lispMappingServiceMock);
final List<IpAddress> ipAddressList = new ArrayList<>();
// hop 1
ipAddressList.add(IPV4_ADDRESS_1);
// hop 2
ipAddressList.add(IPV4_ADDRESS_2);
final Rloc rloc = LispAddressUtil.asTeLcafRloc(ipAddressList);
final LocatorRecordBuilder locatorRecordBuilder_1 = getDefaultLocatorBuilder();
final LocatorRecordBuilder locatorRecordBuilder_2 = getDefaultLocatorBuilder().setRloc(rloc);
// input mapping
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
final MapRequestBuilder mrb = getDefaultMapRequestBuilder();
mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_1)).build());
mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).build());
Mockito.when(mapServiceMock.getMapping(mrb.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
// result
final LocatorRecordBuilder locatorRecordBuilder_3 = getDefaultLocatorBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).setPriority((short) 1);
final MappingRecordBuilder resultMappingRecordBuilder = getDefaultMappingRecordBuilder();
// as Ipv4
resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
// as ELP
resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
// added to the result
resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_3.build());
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(resultMappingRecordBuilder.build()).build());
// invocation
mapResolver.handleMapRequest(mrb.build());
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest__withSubscribers.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
public void handleMapRequest__withSubscribers() {
// 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);
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
Mockito.verify(subscriberSetMock, Mockito.never()).remove(Mockito.any(Subscriber.class));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest_withReplacePolicy.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
public void handleMapRequest_withReplacePolicy() {
mapResolver = new MapResolver(mapServiceMock, true, "replace", lispMappingServiceMock);
final List<IpAddress> ipAddressList = new ArrayList<>();
// hop 1
ipAddressList.add(IPV4_ADDRESS_1);
// hop 2
ipAddressList.add(IPV4_ADDRESS_2);
final Rloc rloc = LispAddressUtil.asTeLcafRloc(ipAddressList);
final LocatorRecordBuilder locatorRecordBuilder_1 = getDefaultLocatorBuilder();
final LocatorRecordBuilder locatorRecordBuilder_2 = getDefaultLocatorBuilder().setRloc(rloc);
// input mapping
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
final MapRequestBuilder mrb = getDefaultMapRequestBuilder();
mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_1)).build());
mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).build());
Mockito.when(mapServiceMock.getMapping(mrb.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
// result
final LocatorRecordBuilder locatorRecordBuilder_3 = getDefaultLocatorBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2));
final MappingRecordBuilder resultMappingRecordBuilder = getDefaultMappingRecordBuilder();
// as Ipv4
resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
// added to the result
resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_3.build());
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(resultMappingRecordBuilder.build()).build());
// invocation
mapResolver.handleMapRequest(mrb.build());
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
Aggregations