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;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
15 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
16 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
28 * DataListener for all AuthenticationKey modification events.
30 * @author Lorand Jakab
33 public class AuthenticationKeyDataListener extends AbstractDataListener<AuthenticationKey> {
34 private static final Logger LOG = LoggerFactory.getLogger(AuthenticationKeyDataListener.class);
35 private IMappingSystem mapSystem;
37 public AuthenticationKeyDataListener(DataBroker broker, IMappingSystem mapSystem) {
39 setMappingSystem(mapSystem);
40 setPath(InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
41 .child(AuthenticationKey.class));
42 LOG.trace("Registering AuthenticationKey listener.");
43 registerDataChangeListener();
47 public void onDataTreeChanged(Collection<DataTreeModification<AuthenticationKey>> changes) {
48 for (DataTreeModification<AuthenticationKey> change : changes) {
49 final DataObjectModification<AuthenticationKey> mod = change.getRootNode();
51 if (ModificationType.DELETE == mod.getModificationType()) {
52 final AuthenticationKey authKey = mod.getDataBefore();
54 LOG.trace("Received deleted data");
55 LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
56 LOG.trace("Value: {}", authKey);
58 final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
60 mapSystem.removeAuthenticationKey(convertedAuthKey.getEid());
61 } else if (ModificationType.WRITE == mod.getModificationType() || ModificationType.SUBTREE_MODIFIED == mod
62 .getModificationType()) {
63 if (ModificationType.WRITE == mod.getModificationType()) {
64 LOG.trace("Received created data");
66 LOG.trace("Received updated data");
68 // Process newly created or updated authentication keys
69 final AuthenticationKey authKey = mod.getDataAfter();
71 LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
72 LOG.trace("Value: {}", authKey);
74 final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
76 mapSystem.addAuthenticationKey(convertedAuthKey.getEid(), convertedAuthKey.getMappingAuthkey());
78 LOG.warn("Ignoring unhandled modification type {}", mod.getModificationType());
83 private static AuthenticationKey convertToBinaryIfNecessary(AuthenticationKey authKey) {
84 Eid originalEid = authKey.getEid();
85 if (LispAddressUtil.addressNeedsConversionToBinary(originalEid.getAddress())) {
86 AuthenticationKeyBuilder akb = new AuthenticationKeyBuilder(authKey);
87 akb.setEid(LispAddressUtil.convertToBinary(originalEid));
93 void setMappingSystem(IMappingSystem msmr) {
94 this.mapSystem = msmr;