use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class LispSouthboundHandler method handleMapRegister.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleMapRegister(ByteBuffer inBuffer, InetAddress sourceAddress, int port) {
try {
Map.Entry<MapRegisterCacheKey, byte[]> artificialEntry = null;
MapRegisterCacheKey cacheKey = null;
MapRegisterCacheValue cacheValue = null;
if (lispSbPlugin.isMapRegisterCacheEnabled()) {
artificialEntry = MapRegisterPartialDeserializer.deserializePartially(inBuffer, sourceAddress);
cacheKey = artificialEntry == null ? null : artificialEntry.getKey();
cacheValue = resolveCacheValue(artificialEntry);
}
if (cacheValue != null) {
lispSbPlugin.getStats().incrementCacheHits();
MapRegisterCacheMetadata mapRegisterMeta = cacheValue.getMapRegisterCacheMetadata();
LOG.debug("Map register message site-ID: {} xTR-ID: {} from cache.", mapRegisterMeta.getSiteId(), mapRegisterMeta.getXtrId());
cacheValue = refreshEntry(cacheKey);
if (cacheValue != null) {
lispSbPlugin.sendNotificationIfPossible(createMappingKeepAlive(cacheValue));
if (cacheValue.getMapRegisterCacheMetadata().isWantMapNotify()) {
sendMapNotifyMsg(inBuffer, sourceAddress, port, cacheValue);
}
}
} else {
lispSbPlugin.getStats().incrementCacheMisses();
MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer, sourceAddress);
MappingAuthkey mappingAuthkey = null;
if (authenticationEnabled) {
mappingAuthkey = tryToAuthenticateMessage(mapRegister, inBuffer);
if (mappingAuthkey == null) {
return;
}
}
AddMappingBuilder addMappingBuilder = new AddMappingBuilder();
addMappingBuilder.setMapRegister(LispNotificationHelper.convertMapRegister(mapRegister));
TransportAddressBuilder transportAddressBuilder = new TransportAddressBuilder();
transportAddressBuilder.setIpAddress(LispNotificationHelper.getIpAddressBinaryFromInetAddress(sourceAddress));
transportAddressBuilder.setPort(new PortNumber(port));
addMappingBuilder.setTransportAddress(transportAddressBuilder.build());
lispSbPlugin.sendNotificationIfPossible(addMappingBuilder.build());
if (artificialEntry != null) {
final MapRegisterCacheMetadataBuilder cacheMetadataBldNew = new MapRegisterCacheMetadataBuilder();
cacheMetadataBldNew.setEidLispAddress(provideEidPrefixesFromMessage(mapRegister));
cacheMetadataBldNew.setXtrId(mapRegister.getXtrId());
cacheMetadataBldNew.setSiteId(mapRegister.getSiteId());
cacheMetadataBldNew.setWantMapNotify(mapRegister.isWantMapNotify());
cacheMetadataBldNew.setMergeEnabled(mapRegister.isMergeEnabled());
cacheMetadataBldNew.setTimestamp(System.currentTimeMillis());
final MapRegisterCacheValueBuilder cacheValueBldNew = new MapRegisterCacheValueBuilder();
cacheValueBldNew.setPacketData(artificialEntry.getValue());
cacheValueBldNew.setMappingAuthkey(mappingAuthkey);
cacheValueBldNew.setMapRegisterCacheMetadata(cacheMetadataBldNew.build());
lispSbPlugin.getMapRegisterCache().addEntry(cacheKey, cacheValueBldNew.build());
}
}
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Register (len=" + inBuffer.capacity() + ")", re);
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class LispSouthboundHandler method tryToAuthenticateMessage.
/**
* Checks whether authentication data is valid.
*
* <p>Methods pass through all records from map register message. For the EID of the first record it gets
* authentication key and does validation of authentication data again this authentication key. If it pass
* it just checks for remaining records (and its EID) whether they have the same authentication key stored in
* the authentication key database.
*
* @return Returns authentication key if all of EIDs have the same authentication key or null otherwise
*/
private MappingAuthkey tryToAuthenticateMessage(final MapRegister mapRegister, final ByteBuffer byteBuffer) {
if (lispSbPlugin.getAkdb() == null) {
LOG.debug("Simple map cache wasn't instantieted and set.");
return null;
}
MappingAuthkey firstAuthKey = null;
final List<MappingRecordItem> mappingRecords = mapRegister.getMappingRecordItem();
for (int i = 0; i < mappingRecords.size(); i++) {
final MappingRecordItem recordItem = mappingRecords.get(i);
final MappingRecord mappingRecord = recordItem.getMappingRecord();
if (i == 0) {
firstAuthKey = lispSbPlugin.getAkdb().getAuthenticationKey(mappingRecord.getEid());
if (!LispAuthenticationUtil.validate(mapRegister, byteBuffer, mappingRecord.getEid(), firstAuthKey)) {
return null;
}
} else {
final Eid eid = mappingRecord.getEid();
final MappingAuthkey authKey = lispSbPlugin.getAkdb().getAuthenticationKey(eid);
if (!firstAuthKey.equals(authKey)) {
LOG.debug("Map register packet contained several eids. Authentication keys for first one and for " + "{} are different.", LispAddressStringifier.getString(eid));
return null;
}
}
}
return firstAuthKey;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method registerAddress.
/*
// This registers an IP with a MapRegister, then adds a password via the
// northbound REST API
// and checks that the password works
public void testPasswordExactMatch() throws Exception {
cleanUP();
String ipString = "10.0.0.1";
LispIpv4Address address = LispAddressUtil.asIPAfiAddress(ipString);
int mask = 32;
String pass = "pass";
URL url = createPutURL("key");
String jsonAuthData = createAuthKeyJSON(pass, address, mask);
LOG.trace("Sending this JSON to LISP server: \n" + jsonAuthData);
LOG.trace("Address: " + address);
byte[] expectedSha = new byte[] { (byte) 146, (byte) 234, (byte) 52, (byte) 247, (byte) 186, (byte) 232,
(byte) 31, (byte) 249, (byte) 87,
(byte) 73, (byte) 234, (byte) 54, (byte) 225, (byte) 160, (byte) 129, (byte) 251, (byte) 73, (byte) 53,
(byte) 196, (byte) 62 };
byte[] zeros = new byte[20];
callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
// build a MapRegister
MapRegisterBuilder mapRegister = new MapRegisterBuilder();
mapRegister.setWantMapNotify(true);
mapRegister.setNonce((long) 8);
EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(address));
etlr.setMaskLength((short) mask);
etlr.setRecordTtl(254);
LocatorRecordBuilder record = new LocatorRecordBuilder();
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
etlr.getLocatorRecord().add(record.build());
mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
mapRegister.setAuthenticationData(zeros);
sendMapRegister(mapRegister.build());
assertNoPacketReceived(3000);
mapRegister.setAuthenticationData(expectedSha);
sendMapRegister(mapRegister.build());
assertMapNotifyReceived();
}
public void testPasswordMaskMatch() throws Exception {
cleanUP();
LispIpv4Address addressInRange = LispAddressUtil.asIPAfiAddress("10.20.30.40");
LispIpv4Address addressOutOfRange = LispAddressUtil.asIPAfiAddress("20.40.30.40");
LispIpv4Address range = LispAddressUtil.asIPAfiAddress("10.20.30.0");
int mask = 32;
String pass = "pass";
URL url = createPutURL("key");
String jsonAuthData = createAuthKeyJSON(pass, range, 8);
callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
// build a MapRegister
MapRegisterBuilder mapRegister = new MapRegisterBuilder();
mapRegister.setWantMapNotify(true);
mapRegister.setNonce((long) 8);
EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressInRange));
etlr.setMaskLength((short) mask);
etlr.setRecordTtl(254);
LocatorRecordBuilder record = new LocatorRecordBuilder();
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
etlr.getLocatorRecord().add(record.build());
mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());
mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
mapRegister
.setAuthenticationData(new byte[] { -15, -52, 38, -94, 125, -111, -68, -79, 68, 6, 101, 45, -1, 47, -4,
-67, -113, 104, -110, -71 });
sendMapRegister(mapRegister.build());
assertMapNotifyReceived();
etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressOutOfRange));
mapRegister
.setAuthenticationData(new byte[] { -54, 68, -58, -91, -23, 22, -88, -31, 113, 39, 115, 78, -68, -123,
-71, -14, -99, 67, -23, -73 });
sendMapRegister(mapRegister.build());
assertNoPacketReceived(3000);
}
*/
// takes an address, packs it in a MapRegister and sends it
private void registerAddress(Eid eid) throws SocketTimeoutException {
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
sleepForSeconds(1);
MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build();
sendMapRegister(mapRegister);
MapNotify mapNotify = receiveMapNotify();
assertEquals(8, mapNotify.getNonce().longValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method sendMapRegisterTwiceWithDiffrentValues.
private MapReply sendMapRegisterTwiceWithDiffrentValues(Eid eid, Rloc rloc1, Rloc rloc2) throws SocketTimeoutException {
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
sleepForSeconds(1);
MapRegister mb = createMapRegister(eid, rloc1);
MapNotify mapNotify = lms.handleMapRegister(mb).getLeft();
MapRequest mr = createMapRequest(eid);
MapReply mapReply = lms.handleMapRequest(mr);
assertEquals(mb.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc(), mapReply.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getRloc());
mb = createMapRegister(eid, rloc2);
mapNotify = lms.handleMapRegister(mb).getLeft();
assertEquals(8, mapNotify.getNonce().longValue());
mr = createMapRequest(eid);
sendMapRequest(mr);
mapReply = lms.handleMapRequest(mr);
return mapReply;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method registerSBMapping.
private void registerSBMapping(long iid, String prefix, String locator) {
LOG.debug("Registering Southbound mapping in VNI {} for prefix {}, locator {}" + " via simulated Map-Register a.k.a. handleMapRegister()", iid, prefix, locator);
Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid(iid, prefix);
Rloc rloc = LispAddressUtil.asIpv4Rloc(locator);
MapRegister mr = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid, rloc).build();
lms.handleMapRegister(mr);
sleepForMilliseconds(100);
MappingServiceIntegrationTestUtil.printMapCacheState(mapService);
}
Aggregations