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;
11 import javax.annotation.Nullable;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.flow.classifier.rev160511.sfc.flow.classifiers.attributes.SfcFlowClassifiers;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.flow.classifier.rev160511.sfc.flow.classifiers.attributes.sfc.flow.classifiers.SfcFlowClassifier;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.flow.classifier.rev160511.sfc.flow.classifiers.attributes.sfc.flow.classifiers.SfcFlowClassifierKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.PortPairGroups;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.PortPairs;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pair.groups.PortPairGroup;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pair.groups.PortPairGroupKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPair;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPairKey;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Utility functions to read Neutron models (e.g network, subnet, port, sfc flow classifier
35 * port pair, port group, port chain) from md-sal data store.
37 public class NeutronMdsalHelper {
38 private static final Logger LOG = LoggerFactory.getLogger(NeutronMdsalHelper.class);
39 private static final InstanceIdentifier<SfcFlowClassifiers> FC_IID =
40 InstanceIdentifier.create(Neutron.class).child(SfcFlowClassifiers.class);
41 private static final InstanceIdentifier<Ports> PORTS_IID =
42 InstanceIdentifier.create(Neutron.class).child(Ports.class);
43 private static final InstanceIdentifier<PortPairs> PORT_PAIRS_IID =
44 InstanceIdentifier.create(Neutron.class).child(PortPairs.class);
45 private static final InstanceIdentifier<PortPairGroups> PORT_PAIR_GROUPS_IID =
46 InstanceIdentifier.create(Neutron.class).child(PortPairGroups.class);
48 private final DataBroker dataBroker;
50 public NeutronMdsalHelper(DataBroker dataBroker) {
51 this.dataBroker = dataBroker;
55 public Port getNeutronPort(Uuid portId) {
56 return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
57 LogicalDatastoreType.CONFIGURATION, getNeutronPortPath(portId)).orNull();
61 public PortPair getNeutronPortPair(Uuid portPairId) {
62 return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
63 LogicalDatastoreType.CONFIGURATION, getNeutronPortPairPath(portPairId)).orNull();
67 public PortPairGroup getNeutronPortPairGroup(Uuid portPairGroupId) {
68 return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
69 LogicalDatastoreType.CONFIGURATION, getNeutronPortPairGroupPath(portPairGroupId)).orNull();
73 public SfcFlowClassifier getNeutronFlowClassifier(Uuid flowClassifierId) {
74 return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
75 LogicalDatastoreType.CONFIGURATION, getNeutronSfcFlowClassifierPath(flowClassifierId)).orNull();
78 private InstanceIdentifier<Port> getNeutronPortPath(Uuid portId) {
79 return PORTS_IID.builder().child(Port.class, new PortKey(portId)).build();
82 private InstanceIdentifier<PortPair> getNeutronPortPairPath(Uuid portPairId) {
83 return PORT_PAIRS_IID.builder().child(PortPair.class, new PortPairKey(portPairId)).build();
86 private InstanceIdentifier<PortPairGroup> getNeutronPortPairGroupPath(Uuid portPairGroupId) {
87 return PORT_PAIR_GROUPS_IID.builder().child(PortPairGroup.class, new PortPairGroupKey(portPairGroupId)).build();
90 private InstanceIdentifier<SfcFlowClassifier> getNeutronSfcFlowClassifierPath(Uuid portId) {
91 return FC_IID.builder().child(SfcFlowClassifier.class, new SfcFlowClassifierKey(portId)).build();