blob: 11d88906add9464d6bf54ac60c6979e92d7839ec [file] [log] [blame]
Mahesh Poojary Huawei1110f6b2015-12-02 15:35:38 +05301/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.sfc.manager.impl;
17
18import org.junit.Test;
19
20import java.util.List;
21import java.util.LinkedList;
22
23import org.onlab.packet.IpPrefix;
24import org.onosproject.sfc.manager.SfcService;
25import org.onosproject.vtnrsc.DefaultPortChain;
26import org.onosproject.vtnrsc.DefaultPortPair;
27import org.onosproject.vtnrsc.DefaultPortPairGroup;
28import org.onosproject.vtnrsc.PortChain;
29import org.onosproject.vtnrsc.PortChainId;
30import org.onosproject.vtnrsc.PortPair;
31import org.onosproject.vtnrsc.PortPairGroup;
32import org.onosproject.vtnrsc.PortPairGroupId;
33import org.onosproject.vtnrsc.PortPairId;
34import org.onosproject.vtnrsc.TenantId;
35import org.onosproject.vtnrsc.DefaultFlowClassifier;
36import org.onosproject.vtnrsc.FlowClassifierId;
37import org.onosproject.vtnrsc.VirtualPortId;
38import org.onosproject.vtnrsc.FlowClassifier;
39
40/**
41 * Unit tests for SfcManager class.
42 */
43public class SfcManagerTest {
44 /**
45 * Checks the operation of onPortPairCreated() method.
46 */
47 @Test
48 public void testOnPortPairCreated() {
49 final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
50 final TenantId tenantId = TenantId.tenantId("1");
51 final String name = "PortPair";
52 final String description = "PortPair";
53 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
54 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
55 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
56 PortPair portPair = null;
57 SfcService sfcService = new SfcManager();
58
59 // create port pair
60 portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name).setDescription(description)
61 .setIngress(ingress).setEgress(egress).build();
62 sfcService.onPortPairCreated(portPair);
63 }
64
65 /**
66 * Checks the operation of onPortPairDeleted() method.
67 */
68 @Test
69 public void testOnPortPairDeleted() {
70 final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
71 final TenantId tenantId = TenantId.tenantId("1");
72 final String name = "PortPair";
73 final String description = "PortPair";
74 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
75 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
76 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
77 PortPair portPair = null;
78 SfcService sfcService = new SfcManager();
79
80 // create port pair
81 portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name).setDescription(description)
82 .setIngress(ingress).setEgress(egress).build();
83 sfcService.onPortPairDeleted(portPair);
84 }
85
86 /**
87 * Checks the operation of onPortPairGroupCreated() method.
88 */
89 @Test
90 public void testOnPortPairGroupCreated() {
91 final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
92 final TenantId tenantId = TenantId.tenantId("1");
93 final String name = "PortPairGroup";
94 final String description = "PortPairGroup";
95 final List<PortPairId> portPairIdList = new LinkedList<PortPairId>();
96 DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
97 PortPairGroup portPairGroup = null;
98 SfcService sfcService = new SfcManager();
99
100 // create port-pair-id list
101 PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
102 portPairIdList.add(portPairId);
103 portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
104 portPairIdList.add(portPairId);
105
106 // create port pair
107 portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId).setName(name)
108 .setDescription(description).setPortPairs(portPairIdList).build();
109 sfcService.onPortPairGroupCreated(portPairGroup);
110 }
111
112 /**
113 * Checks the operation of onPortPairGroupDeleted() method.
114 */
115 @Test
116 public void testOnPortPairGroupDeleted() {
117 final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
118 final TenantId tenantId = TenantId.tenantId("1");
119 final String name = "PortPairGroup";
120 final String description = "PortPairGroup";
121 final List<PortPairId> portPairIdList = new LinkedList<PortPairId>();
122 DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
123 PortPairGroup portPairGroup = null;
124 SfcService sfcService = new SfcManager();
125
126 // create port-pair-id list
127 PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
128 portPairIdList.add(portPairId);
129 portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
130 portPairIdList.add(portPairId);
131
132 // create port pair
133 portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId).setName(name)
134 .setDescription(description).setPortPairs(portPairIdList).build();
135 sfcService.onPortPairGroupDeleted(portPairGroup);
136 }
137
138 /**
139 * Checks the operation of onFlowClassifierCreated() method.
140 */
141 @Test
142 public void testOnFlowClassifierCreated() {
143 final String name = "FlowClassifier";
144 final String description = "FlowClassifier";
145 final String ethType = "IPv4";
146 final String protocol = "udp";
147 final int minSrcPortRange = 1024;
148 final int maxSrcPortRange = 5000;
149 final int minDstPortRange = 1024;
150 final int maxDstPortRange = 5000;
151 final FlowClassifierId flowClassifierId = FlowClassifierId.of("71111111-fc23-aeb6-f44b-56dc5e2fb3ae");
152 final TenantId tenantId = TenantId.tenantId("8");
153 final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
154 final IpPrefix dstIpPrefix = IpPrefix.valueOf("100.100.100.100/0");
155 final VirtualPortId virtualSrcPort = VirtualPortId.portId("100");
156 final VirtualPortId virtualDstPort = VirtualPortId.portId("200");
157 DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
158 FlowClassifier flowClassifier = null;
159 SfcService sfcService = new SfcManager();
160
161 // create flow classifier
162 flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId).setTenantId(tenantId)
163 .setName(name).setDescription(description).setEtherType(ethType).setProtocol(protocol)
164 .setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
165 .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
166 .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
167 sfcService.onFlowClassifierCreated(flowClassifier);
168 }
169
170 /**
171 * Checks the operation of onFlowClassifierDeleted() method.
172 */
173 @Test
174 public void testOnFlowClassifierDeleted() {
175 final String name = "FlowClassifier";
176 final String description = "FlowClassifier";
177 final String ethType = "IPv4";
178 final String protocol = "udp";
179 final int minSrcPortRange = 1024;
180 final int maxSrcPortRange = 5000;
181 final int minDstPortRange = 1024;
182 final int maxDstPortRange = 5000;
183 final FlowClassifierId flowClassifierId = FlowClassifierId.of("71111111-fc23-aeb6-f44b-56dc5e2fb3ae");
184 final TenantId tenantId = TenantId.tenantId("8");
185 final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
186 final IpPrefix dstIpPrefix = IpPrefix.valueOf("100.100.100.100/0");
187 final VirtualPortId virtualSrcPort = VirtualPortId.portId("100");
188 final VirtualPortId virtualDstPort = VirtualPortId.portId("200");
189 DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
190 FlowClassifier flowClassifier = null;
191 SfcService sfcService = new SfcManager();
192
193 // create flow classifier
194 flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId).setTenantId(tenantId)
195 .setName(name).setDescription(description).setEtherType(ethType).setProtocol(protocol)
196 .setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
197 .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
198 .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
199 sfcService.onFlowClassifierDeleted(flowClassifier);
200 }
201
202 /**
203 * Checks the operation of onPortChainCreated() method.
204 */
205 @Test
206 public void testOnPortChainCreated() {
207 final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
208 final TenantId tenantId = TenantId.tenantId("1");
209 final String name = "PortChain";
210 final String description = "PortChain";
211 final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>();
212 final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>();
213 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
214 DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
215 PortChain portChain = null;
216 SfcService sfcService = new SfcManager();
217
218 // create list of Port Pair Groups.
219 PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
220 portPairGroupList.add(portPairGroupId);
221 portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
222 portPairGroupList.add(portPairGroupId);
223
224 // create list of Flow classifiers.
225 FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
226 flowClassifierList.add(flowClassifierId);
227 flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
228 flowClassifierList.add(flowClassifierId);
229
230 // create port chain
231 portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description)
232 .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build();
Mahesh Poojary Huawei15092f62015-12-10 11:09:02 +0530233 //sfcService.onPortChainCreated(portChain);
Mahesh Poojary Huawei1110f6b2015-12-02 15:35:38 +0530234 }
235
236 /**
237 * Checks the operation of onPortChainDeleted() method.
238 */
239 @Test
240 public void testOnPortChainDeleted() {
241 final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
242 final TenantId tenantId = TenantId.tenantId("1");
243 final String name = "PortChain";
244 final String description = "PortChain";
245 final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>();
246 final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>();
247 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
248 DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
249 PortChain portChain = null;
250 SfcService sfcService = new SfcManager();
251
252 // create list of Port Pair Groups.
253 PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
254 portPairGroupList.add(portPairGroupId);
255 portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
256 portPairGroupList.add(portPairGroupId);
257
258 // create list of Flow classifiers.
259 FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
260 flowClassifierList.add(flowClassifierId);
261 flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
262 flowClassifierList.add(flowClassifierId);
263
264 // create port chain
265 portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description)
266 .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build();
Mahesh Poojary Huawei15092f62015-12-10 11:09:02 +0530267 //sfcService.onPortChainDeleted(portChain);
Mahesh Poojary Huawei1110f6b2015-12-02 15:35:38 +0530268 }
269}