2 * Copyright 2016 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.sfc.wrapper;
19 import org.onap.sfc.entity.PortChainReq;
20 import org.onap.sfc.entity.PortChainReq4S;
21 import org.onap.sfc.entity.PortPairGroupReq;
22 import org.onap.sfc.entity.PortPairGroupReq4S;
23 import org.onap.sfc.utils.SfcDriverUtil;
24 import org.onap.sfc.entity.ChainParameter;
25 import org.onap.sfc.entity.FlowClassfierReq;
26 import org.onap.sfc.entity.FlowClassfierReq4N;
27 import org.onap.sfc.entity.FlowClassifierReq4S;
28 import org.onap.sfc.entity.PortChainReq4N;
29 import org.onap.sfc.entity.PortPairGroupReq4N;
30 import org.onap.sfc.entity.portpair.PortPairReq;
31 import org.onap.sfc.entity.portpair.PortPairReq4N;
32 import org.onap.sfc.entity.portpair.PortPairReq4S;
33 import org.onap.sfc.entity.portpair.ServiceFunctionParameter;
35 import java.util.ArrayList;
38 public class N2sReqWrapper {
39 public static PortPairReq4S convertPortPair(PortPairReq4N portPairReq4N) {
40 PortPairReq portPairReq = new PortPairReq();
41 portPairReq.setIngress(portPairReq4N.getIngress());
42 portPairReq.setEgress(portPairReq4N.getEgress());
43 ArrayList<ServiceFunctionParameter> serviceFunctionParameters = new ArrayList<ServiceFunctionParameter>();
44 serviceFunctionParameters.addAll(SfcDriverUtil.generateSfParams(portPairReq4N.getSfParam()));
45 portPairReq.setServiceFunctionParameters(serviceFunctionParameters);
46 portPairReq.setUuid(SfcDriverUtil.generateUuid());
47 ArrayList<PortPairReq> portPairList = new ArrayList<PortPairReq>();
48 portPairList.add(portPairReq);
49 PortPairReq4S portPairReq4S = new PortPairReq4S();
50 portPairReq4S.setPortPair(portPairList);
54 public static PortPairGroupReq4S convertPortPairGroup(PortPairGroupReq4N ppg4N) {
55 PortPairGroupReq ppg4S = new PortPairGroupReq();
56 ppg4S.setPortPairs(ppg4N.getPortPairs());
57 ppg4S.setUuid(SfcDriverUtil.generateUuid());
58 PortPairGroupReq4S portPairGroupReq4S = new PortPairGroupReq4S();
59 ArrayList<PortPairGroupReq> portPairGroupReqs = new ArrayList<PortPairGroupReq>();
60 portPairGroupReqs.add(ppg4S);
61 portPairGroupReq4S.setPortPairGroupReqs(portPairGroupReqs);
63 return portPairGroupReq4S;
66 public static FlowClassifierReq4S convertFlowClassfier(FlowClassfierReq4N flowClassfierReq4N) {
67 ArrayList<FlowClassfierReq> flowClassifiers = new ArrayList();
68 FlowClassfierReq flowClassfierReq = new FlowClassfierReq();
69 flowClassfierReq.setProtocol(flowClassfierReq4N.getIp_proto());
70 // flowClassfierReq.setSourcePortRangeMin(Integer.parseInt(flowClassfierReq4N.
71 // getSource_port_range().split(",")[0]));
72 // flowClassfierReq.setSourcePortRangeMax(Integer.parseInt(flowClassfierReq4N.
73 // getSource_port_range().split(",")[1]));
74 // flowClassfierReq.setDestinationPortRangeMin(Integer.parseInt(
75 // flowClassfierReq4N.getDest_port_range().split(",")[0]));
76 // flowClassfierReq.setDestinationPortRangeMax(Integer.parseInt(
77 // flowClassfierReq4N.getDest_port_range().split(",")[1]));
78 flowClassfierReq.setDestinationIpRange(flowClassfierReq4N.getDest_ip_range());
79 flowClassfierReq.setSrcIpRange(flowClassfierReq4N.getSource_ip_range());
80 flowClassfierReq.setIpDscp(flowClassfierReq4N.getDscp());
81 flowClassfierReq.setUuid(SfcDriverUtil.generateUuid());
82 flowClassifiers.add(flowClassfierReq);
83 FlowClassifierReq4S flowClassifierReq4S = new FlowClassifierReq4S();
84 flowClassifierReq4S.setSfcFlowClassifier(flowClassifiers);
86 return flowClassifierReq4S;
89 public static PortChainReq4S converPortChain(PortChainReq4N portChainReq4N) {
90 PortChainReq portChainReq = new PortChainReq();
91 portChainReq.setPortPairGroups(portChainReq4N.getPortPairGroups());
92 portChainReq.setFlowClassifiers(portChainReq4N.getFlowClassifiers());
93 portChainReq.setUuid(SfcDriverUtil.generateUuid());
95 ArrayList<ChainParameter> chainParam = new ArrayList<ChainParameter>();
96 chainParam.add(SfcDriverUtil.generateChainParam("symmetric", portChainReq4N.isSymmetric() ? "true" : "false"));
97 portChainReq.setChainParams(chainParam);
98 ArrayList<PortChainReq> portChains = new ArrayList<PortChainReq>();
99 portChains.add(portChainReq);
100 PortChainReq4S portChainReq4S = new PortChainReq4S();
101 portChainReq4S.setPortChainReqs(portChains);
102 return portChainReq4S;