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;
10 import java.util.Collection;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
14 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
24 * DataListener for all AuthenticationKey modification events.
26 * @author Lorand Jakab
29 public class AuthenticationKeyDataListener extends NewAbstractDataListener<AuthenticationKey> {
30 private static final Logger LOG = LoggerFactory.getLogger(AuthenticationKeyDataListener.class);
31 private IMappingSystem mapSystem;
33 public AuthenticationKeyDataListener(DataBroker broker, IMappingSystem mapSystem) {
35 setMappingSystem(mapSystem);
36 setPath(InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
37 .child(AuthenticationKey.class));
38 LOG.trace("Registering AuthenticationKey listener.");
39 registerDataChangeListener();
43 public void onDataTreeChanged(Collection<DataTreeModification<AuthenticationKey>> changes) {
44 for (DataTreeModification<AuthenticationKey> change : changes) {
45 final DataObjectModification<AuthenticationKey> mod = change.getRootNode();
47 if (ModificationType.DELETE == mod.getModificationType()) {
48 final AuthenticationKey authKey = mod.getDataBefore();
50 LOG.trace("Received deleted data");
51 LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
52 LOG.trace("Value: {}", authKey);
54 mapSystem.removeAuthenticationKey(authKey.getEid());
55 } else if (ModificationType.WRITE == mod.getModificationType() || ModificationType.SUBTREE_MODIFIED == mod
56 .getModificationType()) {
57 if (ModificationType.WRITE == mod.getModificationType()) {
58 LOG.trace("Received created data");
60 LOG.trace("Received updated data");
62 // Process newly created or updated authentication keys
63 final AuthenticationKey authKey = mod.getDataAfter();
65 LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
66 LOG.trace("Value: {}", authKey);
68 mapSystem.addAuthenticationKey(authKey.getEid(), authKey.getMappingAuthkey());
70 LOG.warn("Ignoring unhandled modification type {}", mod.getModificationType());
75 void setMappingSystem(IMappingSystem msmr) {
76 this.mapSystem = msmr;