0ad7d1b455bcaa7362556e970defacc9744ee49e
[vfc/nfvo/driver/sfc.git] / zte / sfc-driver / sfc-driver / src / main / java / org / openo / sfc / wrapper / N2sReqWrapper.java
1 /**
2  * Copyright 2016 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openo.sfc.wrapper;
18
19 import org.openo.sfc.entity.ChainParameter;
20 import org.openo.sfc.entity.FlowClassfierReq;
21 import org.openo.sfc.entity.FlowClassfierReq4N;
22 import org.openo.sfc.entity.FlowClassifierReq4S;
23 import org.openo.sfc.entity.PortChainReq;
24 import org.openo.sfc.entity.PortChainReq4N;
25 import org.openo.sfc.entity.PortChainReq4S;
26 import org.openo.sfc.entity.PortPairGroupReq;
27 import org.openo.sfc.entity.PortPairGroupReq4N;
28 import org.openo.sfc.entity.PortPairGroupReq4S;
29 import org.openo.sfc.entity.portpair.PortPairReq;
30 import org.openo.sfc.entity.portpair.PortPairReq4N;
31 import org.openo.sfc.entity.portpair.PortPairReq4S;
32 import org.openo.sfc.entity.portpair.ServiceFunctionParameter;
33 import org.openo.sfc.utils.SfcDriverUtil;
34
35 import java.util.ArrayList;
36
37
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);
51         return portPairReq4S;
52     }
53
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);
62
63         return portPairGroupReq4S;
64     }
65
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);
85
86         return flowClassifierReq4S;
87     }
88
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());
94
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;
103     }
104
105
106 }