2 * Copyright (c) 2016, 2017 Brocade Communications Systems, Inc. and others. 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
9 package org.opendaylight.netvirt.sfc.translator.portchain;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.netvirt.sfc.translator.DelegatingDataTreeListener;
15 import org.opendaylight.netvirt.sfc.translator.SfcMdsalHelper;
16 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SffName;
17 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunctionKey;
18 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
19 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarderKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.PortPairs;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPair;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * OpenDaylight Neutron Port Pair yang models data change listener.
30 public class NeutronPortPairListener extends DelegatingDataTreeListener<PortPair> {
31 private static final Logger LOG = LoggerFactory.getLogger(NeutronPortPairListener.class);
33 private static final InstanceIdentifier<PortPair> PORT_PAIR_IID =
34 InstanceIdentifier.create(Neutron.class).child(PortPairs.class).child(PortPair.class);
36 private final SfcMdsalHelper sfcMdsalHelper;
38 public NeutronPortPairListener(DataBroker db) {
39 super(db,new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, PORT_PAIR_IID));
40 sfcMdsalHelper = new SfcMdsalHelper(db);
44 * Method removes PortPair which is identified by InstanceIdentifier.
46 * @param deletedPortPair - PortPair for removing
49 public void remove(PortPair deletedPortPair) {
50 LOG.info("Received remove port pair event {}", deletedPortPair);
52 ServiceFunctionKey sfKey = PortPairTranslator.getSFKey(deletedPortPair);
53 LOG.info("Removing service function {}", sfKey);
54 sfcMdsalHelper.removeServiceFunction(sfKey);
56 ServiceFunctionForwarder sff;
57 ServiceFunctionForwarder updatedSff;
58 SffName sffName = new SffName(SfcMdsalHelper.NETVIRT_LOGICAL_SFF_NAME);
59 sff = sfcMdsalHelper.readServiceFunctionForwarder(new ServiceFunctionForwarderKey(sffName));
60 updatedSff = PortPairGroupTranslator.removePortPairFromServiceFunctionForwarder(sff, deletedPortPair);
61 LOG.info("Updating service function forwarder as {}", updatedSff);
62 sfcMdsalHelper.addServiceFunctionForwarder(updatedSff);
66 * Method updates the original PortPair to the update PortPair.
67 * Both are identified by same InstanceIdentifier.
69 * @param updatePortPair - changed PortPair (contain updates)
72 public void update(PortPair updatePortPair) {
77 * Method adds the PortPair which is identified by InstanceIdentifier
80 * @param newPortPair - new PortPair
83 public void add(PortPair newPortPair) {
85 // Port Pair data written in neutron data store will be used
86 // When user will create port chain.