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.implementation.LispMappingService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.MappingDatabase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.db.instance.AuthenticationKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.mapping.database.InstanceId;
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 LispMappingService msmr;
34 public AuthenticationKeyDataListener(DataBroker broker, LispMappingService msmr) {
37 setPath(InstanceIdentifier.create(MappingDatabase.class).child(InstanceId.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 msmr.addAuthenticationKey(authkey.getLispAddressContainer(),
58 authkey.getMaskLength(), authkey.getAuthkey());
62 // Process updated authentication keys
63 Map<InstanceIdentifier<?>, DataObject> updatedData = change.getUpdatedData();
64 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : updatedData.entrySet()) {
65 if (entry.getValue() instanceof AuthenticationKey) {
66 AuthenticationKey authkey = (AuthenticationKey)entry.getValue();
68 LOG.trace("Received changed data");
69 LOG.trace("Key: {}", entry.getKey());
70 LOG.trace("Value: {}", authkey);
72 msmr.addAuthenticationKey(authkey.getLispAddressContainer(),
73 authkey.getMaskLength(), authkey.getAuthkey());
77 // Process deleted authentication keys
78 Set<InstanceIdentifier<?>> removedData = change.getRemovedPaths();
79 for (InstanceIdentifier<?> entry : removedData) {
80 DataObject dataObject = change.getOriginalData().get(entry);
81 if (dataObject instanceof AuthenticationKey) {
82 AuthenticationKey authkey = (AuthenticationKey)dataObject;
84 LOG.trace("Received deleted data");
85 LOG.trace("Key: {}", entry);
86 LOG.trace("Value: {}", authkey);
88 msmr.removeAuthenticationKey(authkey.getLispAddressContainer(), authkey.getMaskLength());
93 void setMsmr(LispMappingService msmr) {