*/
package org.opendaylight.lispflowmapping.implementation.mdsal;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import java.util.List;
import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.InstanceId;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author Lorand Jakab
*
*/
-public class AuthenticationKeyDataListener extends AbstractDataListener {
+public class AuthenticationKeyDataListener extends AbstractDataListener<AuthenticationKey> {
private static final Logger LOG = LoggerFactory.getLogger(AuthenticationKeyDataListener.class);
private IMappingSystem mapSystem;
public AuthenticationKeyDataListener(DataBroker broker, IMappingSystem mapSystem) {
setBroker(broker);
setMappingSystem(mapSystem);
- setPath(InstanceIdentifier.create(MappingDatabase.class).child(InstanceId.class)
+ setPath(InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
.child(AuthenticationKey.class));
LOG.trace("Registering AuthenticationKey listener.");
registerDataChangeListener();
}
@Override
- public void onDataChanged(
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ public void onDataTreeChanged(List<DataTreeModification<AuthenticationKey>> changes) {
+ for (DataTreeModification<AuthenticationKey> change : changes) {
+ final DataObjectModification<AuthenticationKey> mod = change.getRootNode();
- // Process newly created authentication keys
- Map<InstanceIdentifier<?>, DataObject> createdData = change.getCreatedData();
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : createdData.entrySet()) {
- if (entry.getValue() instanceof AuthenticationKey) {
- AuthenticationKey authkey = (AuthenticationKey)entry.getValue();
+ if (ModificationType.DELETE == mod.modificationType()) {
+ final AuthenticationKey authKey = mod.dataBefore();
- LOG.trace("Received created data");
- LOG.trace("Key: {}", entry.getKey());
- LOG.trace("Value: {}", authkey);
+ LOG.trace("Received deleted data");
+ LOG.trace("Key: {}", change.getRootPath().path());
+ LOG.trace("Value: {}", authKey);
- mapSystem.addAuthenticationKey(authkey.getLispAddressContainer(), authkey.getAuthkey());
- }
- }
+ final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
+
+ mapSystem.removeAuthenticationKey(convertedAuthKey.getEid());
+ } else if (ModificationType.WRITE == mod.modificationType()
+ || ModificationType.SUBTREE_MODIFIED == mod.modificationType()) {
+ if (ModificationType.WRITE == mod.modificationType()) {
+ LOG.trace("Received created data");
+ } else {
+ LOG.trace("Received updated data");
+ }
+ // Process newly created or updated authentication keys
+ final AuthenticationKey authKey = mod.dataAfter();
- // Process updated authentication keys
- Map<InstanceIdentifier<?>, DataObject> updatedData = change.getUpdatedData();
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : updatedData.entrySet()) {
- if (entry.getValue() instanceof AuthenticationKey) {
- AuthenticationKey authkey = (AuthenticationKey)entry.getValue();
+ LOG.trace("Key: {}", change.getRootPath().path());
+ LOG.trace("Value: {}", authKey);
- LOG.trace("Received changed data");
- LOG.trace("Key: {}", entry.getKey());
- LOG.trace("Value: {}", authkey);
+ final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
- mapSystem.addAuthenticationKey(authkey.getLispAddressContainer(), authkey.getAuthkey());
+ mapSystem.addAuthenticationKey(convertedAuthKey.getEid(), convertedAuthKey.getMappingAuthkey());
+ } else {
+ LOG.warn("Ignoring unhandled modification type {}", mod.modificationType());
}
}
+ }
- // Process deleted authentication keys
- Set<InstanceIdentifier<?>> removedData = change.getRemovedPaths();
- for (InstanceIdentifier<?> entry : removedData) {
- DataObject dataObject = change.getOriginalData().get(entry);
- if (dataObject instanceof AuthenticationKey) {
- AuthenticationKey authkey = (AuthenticationKey)dataObject;
-
- LOG.trace("Received deleted data");
- LOG.trace("Key: {}", entry);
- LOG.trace("Value: {}", authkey);
-
- mapSystem.removeAuthenticationKey(authkey.getLispAddressContainer());
- }
+ private static AuthenticationKey convertToBinaryIfNecessary(AuthenticationKey authKey) {
+ Eid originalEid = authKey.getEid();
+ if (LispAddressUtil.addressNeedsConversionToBinary(originalEid.getAddress())) {
+ AuthenticationKeyBuilder akb = new AuthenticationKeyBuilder(authKey);
+ akb.setEid(LispAddressUtil.convertToBinary(originalEid));
+ return akb.build();
}
+ return authKey;
}
void setMappingSystem(IMappingSystem msmr) {
- this.mapSystem = msmr;
+ mapSystem = msmr;
}
}