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.List;
11 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
12 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.mdsal.binding.api.DataObjectModification;
15 import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
16 import org.opendaylight.mdsal.binding.api.DataTreeModification;
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;
27 * DataListener for all AuthenticationKey modification events.
29 * @author Lorand Jakab
32 public class AuthenticationKeyDataListener extends AbstractDataListener<AuthenticationKey> {
33 private static final Logger LOG = LoggerFactory.getLogger(AuthenticationKeyDataListener.class);
34 private IMappingSystem mapSystem;
36 public AuthenticationKeyDataListener(DataBroker broker, IMappingSystem mapSystem) {
38 setMappingSystem(mapSystem);
39 setPath(InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
40 .child(AuthenticationKey.class));
41 LOG.trace("Registering AuthenticationKey listener.");
42 registerDataChangeListener();
46 public void onDataTreeChanged(List<DataTreeModification<AuthenticationKey>> changes) {
47 for (DataTreeModification<AuthenticationKey> change : changes) {
48 final DataObjectModification<AuthenticationKey> mod = change.getRootNode();
50 if (ModificationType.DELETE == mod.modificationType()) {
51 final AuthenticationKey authKey = mod.dataBefore();
53 LOG.trace("Received deleted data");
54 LOG.trace("Key: {}", change.getRootPath().path());
55 LOG.trace("Value: {}", authKey);
57 final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
59 mapSystem.removeAuthenticationKey(convertedAuthKey.getEid());
60 } else if (ModificationType.WRITE == mod.modificationType()
61 || ModificationType.SUBTREE_MODIFIED == mod.modificationType()) {
62 if (ModificationType.WRITE == mod.modificationType()) {
63 LOG.trace("Received created data");
65 LOG.trace("Received updated data");
67 // Process newly created or updated authentication keys
68 final AuthenticationKey authKey = mod.dataAfter();
70 LOG.trace("Key: {}", change.getRootPath().path());
71 LOG.trace("Value: {}", authKey);
73 final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
75 mapSystem.addAuthenticationKey(convertedAuthKey.getEid(), convertedAuthKey.getMappingAuthkey());
77 LOG.warn("Ignoring unhandled modification type {}", mod.modificationType());
82 private static AuthenticationKey convertToBinaryIfNecessary(AuthenticationKey authKey) {
83 Eid originalEid = authKey.getEid();
84 if (LispAddressUtil.addressNeedsConversionToBinary(originalEid.getAddress())) {
85 AuthenticationKeyBuilder akb = new AuthenticationKeyBuilder(authKey);
86 akb.setEid(LispAddressUtil.convertToBinary(originalEid));
92 void setMappingSystem(IMappingSystem msmr) {