2 * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.implementation.mdsal;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * DataListener for all AuthenticationKey modification events.
27 * @author Lorand Jakab
30 public class AuthenticationKeyDataListener extends AbstractDataListener {
31 private static final Logger LOG = LoggerFactory.getLogger(AuthenticationKeyDataListener.class);
32 private IMappingSystem mapSystem;
34 public AuthenticationKeyDataListener(DataBroker broker, IMappingSystem mapSystem) {
36 setMappingSystem(mapSystem);
37 setPath(InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
38 .child(AuthenticationKey.class));
39 LOG.trace("Registering AuthenticationKey listener.");
40 registerDataChangeListener();
44 public void onDataChanged(
45 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
47 // Process newly created authentication keys
48 Map<InstanceIdentifier<?>, DataObject> createdData = change.getCreatedData();
49 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : createdData.entrySet()) {
50 if (entry.getValue() instanceof AuthenticationKey) {
51 AuthenticationKey authkey = (AuthenticationKey)entry.getValue();
53 LOG.trace("Received created data");
54 LOG.trace("Key: {}", entry.getKey());
55 LOG.trace("Value: {}", authkey);
57 mapSystem.addAuthenticationKey(authkey.getEid(), authkey.getMappingAuthkey());
61 // Process updated authentication keys
62 Map<InstanceIdentifier<?>, DataObject> updatedData = change.getUpdatedData();
63 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : updatedData.entrySet()) {
64 if (entry.getValue() instanceof AuthenticationKey) {
65 AuthenticationKey authkey = (AuthenticationKey)entry.getValue();
67 LOG.trace("Received changed data");
68 LOG.trace("Key: {}", entry.getKey());
69 LOG.trace("Value: {}", authkey);
71 mapSystem.addAuthenticationKey(authkey.getEid(), authkey.getMappingAuthkey());
75 // Process deleted authentication keys
76 Set<InstanceIdentifier<?>> removedData = change.getRemovedPaths();
77 for (InstanceIdentifier<?> entry : removedData) {
78 DataObject dataObject = change.getOriginalData().get(entry);
79 if (dataObject instanceof AuthenticationKey) {
80 AuthenticationKey authkey = (AuthenticationKey)dataObject;
82 LOG.trace("Received deleted data");
83 LOG.trace("Key: {}", entry);
84 LOG.trace("Value: {}", authkey);
86 mapSystem.removeAuthenticationKey(authkey.getEid());
91 void setMappingSystem(IMappingSystem msmr) {
92 this.mapSystem = msmr;