use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress in project lispflowmapping by opendaylight.
the class LispSouthboundRpcTest method sendMapRegisterTest_inputNotNull.
/**
* Tests {@link LispSouthboundRPC#sendMapRegister} method.
*/
@Test
public void sendMapRegisterTest_inputNotNull() throws ExecutionException, InterruptedException {
final MapRegister mapRegister = getDefaultMapRegisterBuilder().build();
final TransportAddress transportAddress = new TransportAddressBuilder().build();
final SendMapRegisterInput sendMapRegisterInputMock = Mockito.mock(SendMapRegisterInput.class);
Mockito.when(sendMapRegisterInputMock.getTransportAddress()).thenReturn(transportAddress);
Mockito.when(sendMapRegisterInputMock.getMapRegister()).thenReturn(mapRegister);
assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), lispSouthboundRPC.sendMapRegister(sendMapRegisterInputMock).get().isSuccessful());
Mockito.verify(lispSouthboundPlugin).handleSerializedLispBuffer(transportAddress, MapRegisterSerializer.getInstance().serialize(mapRegister), MessageType.MapRegister);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress in project lispflowmapping by opendaylight.
the class LispSouthboundPlugin method getInetAddress.
private InetAddress getInetAddress(TransportAddress address) {
Preconditions.checkNotNull(address, "TransportAddress must not be null");
IpAddressBinary ip = address.getIpAddress();
try {
if (ip.getIpv4AddressBinary() != null) {
return InetAddress.getByAddress(ip.getIpv4AddressBinary().getValue());
} else if (ip.getIpv6AddressBinary() != null) {
return InetAddress.getByAddress(ip.getIpv6AddressBinary().getValue());
}
} catch (UnknownHostException e) {
LOG.debug("Could not convert TransportAddress {} to InetAddress", address, e);
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress in project lispflowmapping by opendaylight.
the class MapServer method handleMapRegister.
@SuppressWarnings("unchecked")
public void handleMapRegister(MapRegister mapRegister) {
boolean mappingUpdated = false;
boolean merge = ConfigIni.getInstance().mappingMergeIsSet() && mapRegister.isMergeEnabled();
MappingRecord oldMapping;
if (merge) {
if (!mapRegister.isXtrSiteIdPresent() || mapRegister.getXtrId() == null) {
LOG.error("Merge bit is set in Map-Register, but xTR-ID is not present. Will not merge.");
merge = false;
} else if (Arrays.equals(mapRegister.getXtrId().getValue(), ALL_ZEROES_XTR_ID)) {
LOG.warn("Merge bit is set in Map-Register, but xTR-ID is all zeroes.");
}
}
for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
MappingRecord mapping = record.getMappingRecord();
Eid eid = mapping.getEid();
MappingData mappingData = new MappingData(mapping, System.currentTimeMillis());
mappingData.setMergeEnabled(merge);
mappingData.setXtrId(mapRegister.getXtrId());
oldMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
mapService.addMapping(MappingOrigin.Southbound, eid, getSiteId(mapRegister), mappingData);
if (merge) {
MappingRecord newMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
if (MappingRecordUtil.mappingChanged(oldMapping, newMapping)) {
// If there is a SB mapping change with merge on, Map-Notify will be sent to ALL xTRs, not jus the
// one registering (merging is done in the MappingSystem code)
mappingUpdated = true;
}
}
}
if (BooleanUtils.isTrue(mapRegister.isWantMapNotify())) {
LOG.trace("MapRegister wants MapNotify");
MapNotifyBuilder builder = new MapNotifyBuilder();
List<TransportAddress> rlocs = null;
if (merge) {
Set<IpAddressBinary> notifyRlocs = new HashSet<IpAddressBinary>();
List<MappingRecordItem> mergedMappings = new ArrayList<MappingRecordItem>();
for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
MappingRecord mapping = record.getMappingRecord();
MappingRecord currentRecord = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, mapping.getEid()));
mergedMappings.add(new MappingRecordItemBuilder().setMappingRecord(currentRecord).build());
Set<IpAddressBinary> sourceRlocs = (Set<IpAddressBinary>) mapService.getData(MappingOrigin.Southbound, mapping.getEid(), SubKeys.SRC_RLOCS);
if (sourceRlocs != null) {
notifyRlocs.addAll(sourceRlocs);
}
}
MapNotifyBuilderHelper.setFromMapRegisterAndMappingRecordItems(builder, mapRegister, mergedMappings);
// send map-notify to merge group only when mapping record is changed
if (mappingUpdated) {
rlocs = getTransportAddresses(notifyRlocs);
}
} else {
MapNotifyBuilderHelper.setFromMapRegister(builder, mapRegister);
}
List<MappingRecordItem> mappings = builder.getMappingRecordItem();
if (mappings != null && mappings.get(0) != null && mappings.get(0).getMappingRecord() != null && mappings.get(0).getMappingRecord().getEid() != null) {
MappingAuthkey authkey = mapService.getAuthenticationKey(mappings.get(0).getMappingRecord().getEid());
if (authkey != null) {
builder.setAuthenticationData(LispAuthenticationUtil.createAuthenticationData(builder.build(), authkey.getKeyString()));
}
}
notifyHandler.handleMapNotify(builder.build(), rlocs);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress in project lispflowmapping by opendaylight.
the class MapServer method getTransportAddresses.
private static List<TransportAddress> getTransportAddresses(Set<IpAddressBinary> addresses) {
List<TransportAddress> rlocs = new ArrayList<TransportAddress>();
for (IpAddressBinary address : addresses) {
TransportAddressBuilder tab = new TransportAddressBuilder();
tab.setIpAddress(address);
tab.setPort(new PortNumber(LispMessage.PORT_NUM));
rlocs.add(tab.build());
}
return rlocs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress in project lispflowmapping by opendaylight.
the class LispNotificationHelper method getTransportAddressFromRloc.
public static TransportAddress getTransportAddressFromRloc(Rloc rloc) {
TransportAddressBuilder tab = new TransportAddressBuilder();
Address address = rloc.getAddress();
// object, yey!
if (address instanceof Ipv4) {
String ipv4 = ((Ipv4) address).getIpv4().getValue();
tab.setIpAddress(IpAddressBinaryBuilder.getDefaultInstance(InetAddresses.forString(ipv4).getAddress()));
tab.setPort(new PortNumber(LispMessage.PORT_NUM));
} else if (address instanceof Ipv6) {
String ipv6 = ((Ipv6) address).getIpv6().getValue();
tab.setIpAddress(IpAddressBinaryBuilder.getDefaultInstance(InetAddresses.forString(ipv6).getAddress()));
tab.setPort(new PortNumber(LispMessage.PORT_NUM));
} else if (address instanceof Ipv4Binary) {
Ipv4AddressBinary ipv6 = ((Ipv4Binary) address).getIpv4Binary();
tab.setIpAddress(new IpAddressBinary(ipv6));
tab.setPort(new PortNumber(LispMessage.PORT_NUM));
} else if (address instanceof Ipv6Binary) {
Ipv6AddressBinary ipv6 = ((Ipv6Binary) address).getIpv6Binary();
tab.setIpAddress(new IpAddressBinary(ipv6));
tab.setPort(new PortNumber(LispMessage.PORT_NUM));
} else if (address instanceof KeyValueAddress) {
SimpleAddress sa = ((KeyValueAddress) address).getKeyValueAddress().getValue();
if (sa.getDistinguishedNameType() != null) {
final Iterator<String> it = COLON_SPLITTER.split(sa.getDistinguishedNameType().getValue()).iterator();
String ip = it.next();
int port = Integer.valueOf(it.next());
tab.setIpAddress(IpAddressBinaryBuilder.getDefaultInstance(InetAddresses.forString(ip).getAddress()));
tab.setPort(new PortNumber(port));
}
} else if (address instanceof DistinguishedName) {
DistinguishedName dname = (DistinguishedName) address;
final Iterator<String> it = COLON_SPLITTER.split(dname.getDistinguishedName().getValue()).iterator();
String ip = it.next();
int port = Integer.valueOf(it.next());
tab.setIpAddress(IpAddressBinaryBuilder.getDefaultInstance(InetAddresses.forString(ip).getAddress()));
tab.setPort(new PortNumber(port));
} else if (address instanceof ApplicationData) {
ApplicationData appData = (ApplicationData) address;
tab.setIpAddress(getIpAddressBinary(appData.getApplicationData().getAddress().getIpAddress()));
tab.setPort(new PortNumber(appData.getApplicationData().getLocalPortLow()));
}
return tab.build();
}
Aggregations