5b3baeacb278952ae6c7fd6ed790d3915d2e698c
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronSFCPortPairInterface.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.neutron.transcriber;
9
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.neutron.spi.INeutronSFCPortPairCRUD;
15 import org.opendaylight.neutron.spi.NeutronSFCPortPair;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.pair.attributes.ServiceFunctionParameters;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.pair.attributes.ServiceFunctionParametersBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.pair.attributes.ServiceFunctionParametersKey;
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.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPairBuilder;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * Created by Anil Vishnoi (avishnoi@Brocade.com)
30  */
31 public final class NeutronSFCPortPairInterface extends AbstractNeutronInterface<PortPair, PortPairs, NeutronSFCPortPair>
32         implements INeutronSFCPortPairCRUD {
33
34     private static final Logger LOGGER = LoggerFactory.getLogger(NeutronSFCPortPairInterface.class);
35
36     NeutronSFCPortPairInterface(DataBroker db) {
37         super(PortPairBuilder.class, db);
38     }
39
40     @Override
41     protected InstanceIdentifier<PortPair> createInstanceIdentifier(PortPair portPair) {
42         return InstanceIdentifier.create(Neutron.class).child(PortPairs.class).child(PortPair.class, portPair.getKey());
43     }
44
45     @Override
46     protected PortPair toMd(NeutronSFCPortPair neutronPortPair) {
47
48         LOGGER.trace("toMd: REST SFC Port Pair data : {}", neutronPortPair);
49
50         PortPairBuilder result = new PortPairBuilder();
51         toMdBaseAttributes(neutronPortPair, result);
52         if (neutronPortPair.getIngressPortUUID() != null) {
53             result.setIngress(new Uuid(neutronPortPair.getIngressPortUUID()));
54         }
55         if (neutronPortPair.getEgressPortUUID() != null) {
56             result.setEgress(new Uuid(neutronPortPair.getEgressPortUUID()));
57         }
58         if (neutronPortPair.getServiceFunctionParameters() != null) {
59             List<ServiceFunctionParameters> serviceFunctionParams = new ArrayList<>();
60             for (String paramKey : neutronPortPair.getServiceFunctionParameters().keySet()) {
61                 ServiceFunctionParametersBuilder param = new ServiceFunctionParametersBuilder();
62                 param.setKey(new ServiceFunctionParametersKey(paramKey));
63                 param.setServiceFunctionParameter(paramKey);
64                 param.setServiceFunctionParameterValue(neutronPortPair.getServiceFunctionParameters().get(paramKey));
65                 serviceFunctionParams.add(param.build());
66             }
67             result.setServiceFunctionParameters(serviceFunctionParams);
68         }
69         LOGGER.trace("toMd: Yang SFC Port Pair data : {}", result);
70         return result.build();
71     }
72
73     @Override
74     protected NeutronSFCPortPair fromMd(PortPair mdPortPair) {
75         LOGGER.trace("fromMd: Yang SFC Port Pair data : {}", mdPortPair);
76         NeutronSFCPortPair result = new NeutronSFCPortPair();
77         fromMdBaseAttributes(mdPortPair, result);
78         if (mdPortPair.getIngress() != null) {
79             result.setIngressPortUUID(mdPortPair.getIngress().getValue());
80         }
81         if (mdPortPair.getEgress() != null) {
82             result.setEgressPortUUID(mdPortPair.getEgress().getValue());
83         }
84         if (mdPortPair.getServiceFunctionParameters() != null) {
85             HashMap<String, String> serviceFunctionParam = new HashMap<>();
86             for (ServiceFunctionParameters param : mdPortPair.getServiceFunctionParameters()) {
87                 serviceFunctionParam.put(param.getServiceFunctionParameter(), param.getServiceFunctionParameterValue());
88             }
89             result.setServiceFunctionParameters(serviceFunctionParam);
90         }
91         LOGGER.trace("fromMd: REST SFC Port Pair data : {}", result);
92         return result;
93     }
94
95     @Override
96     protected List<PortPair> getDataObjectList(PortPairs dataObjects) {
97         return dataObjects.getPortPair();
98     }
99
100 }