Mahesh Poojary Huawei

[ONOS-3163] Testing on Flow Classifier Manager

Change-Id: I3b9d7ba080dac7fa54284361fe7c181174c4d65b
1 +/*
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 + */
16 +package org.onosproject.vtnrsc.flowclassifier.impl;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import org.onlab.packet.IpPrefix;
25 +
26 +import org.onosproject.vtnrsc.TenantId;
27 +import org.onosproject.vtnrsc.DefaultFlowClassifier;
28 +import org.onosproject.vtnrsc.FlowClassifierId;
29 +import org.onosproject.vtnrsc.VirtualPortId;
30 +import org.onosproject.vtnrsc.FlowClassifier;
31 +import org.onosproject.vtnrsc.util.VtnStorageServiceTest;
32 +
33 +/**
34 + * Unit tests for FlowClassifierManager class.
35 + */
36 +public class FlowClassifierManagerTest {
37 +
38 + final String name = "FlowClassifier";
39 + final String description = "FlowClassifier";
40 + final String ethType = "IPv4";
41 + final String protocol = "udp";
42 + final int minSrcPortRange = 1024;
43 + final int maxSrcPortRange = 5000;
44 + final int minDstPortRange = 1024;
45 + final int maxDstPortRange = 5000;
46 + final FlowClassifierId flowClassifierId = FlowClassifierId.of("71111111-fc23-aeb6-f44b-56dc5e2fb3ae");
47 + final TenantId tenantId = TenantId.tenantId("8");
48 + final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
49 + final IpPrefix dstIpPrefix = IpPrefix.valueOf("100.100.100.100/0");
50 + final VirtualPortId virtualSrcPort = VirtualPortId.portId("100");
51 + final VirtualPortId virtualDstPort = VirtualPortId.portId("200");
52 + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
53 + FlowClassifierManager flowClassifierMgr = new FlowClassifierManager();
54 + FlowClassifier flowClassifier = null;
55 + private final VtnStorageServiceTest storageService = new VtnStorageServiceTest();
56 +
57 + /**
58 + * Checks the operation of createFlowClassifier() method.
59 + */
60 + @Test
61 + public void testCreateFlowClassifier() {
62 + // initialize flow classifier manager
63 + flowClassifierMgr.storageService = storageService;
64 + flowClassifierMgr.activate();
65 +
66 + // create flow classifier
67 + flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId).setTenantId(tenantId)
68 + .setName(name).setDescription(description).setEtherType(ethType).setProtocol(protocol)
69 + .setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
70 + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
71 + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
72 + assertThat(flowClassifierMgr.createFlowClassifier(flowClassifier), is(true));
73 + }
74 +
75 + /**
76 + * Checks the operation of exists() method.
77 + */
78 + @Test
79 + public void testExists() {
80 + testCreateFlowClassifier();
81 + assertThat(flowClassifierMgr.exists(flowClassifierId), is(true));
82 + }
83 +
84 + /**
85 + * Checks the operation of getFlowClassifierCount() method.
86 + */
87 + @Test
88 + public void testGetFlowClassifierCount() {
89 + testCreateFlowClassifier();
90 + assertThat(flowClassifierMgr.getFlowClassifierCount(), is(1));
91 + }
92 +
93 + /**
94 + * Checks the operation of getFlowClassifiers() method.
95 + */
96 + @Test
97 + public void testGetFlowClassifiers() {
98 + testCreateFlowClassifier();
99 + final Iterable<FlowClassifier> flowClassifierList = flowClassifierMgr.getFlowClassifiers();
100 + assertThat(flowClassifierList, is(notNullValue()));
101 + assertThat(flowClassifierList.iterator().hasNext(), is(true));
102 + }
103 +
104 + /**
105 + * Checks the operation of getFlowClassifier() method.
106 + */
107 + @Test
108 + public void testGetFlowClassifier() {
109 + testCreateFlowClassifier();
110 + assertThat(flowClassifier, is(notNullValue()));
111 + assertThat(flowClassifierMgr.getFlowClassifier(flowClassifierId), is(flowClassifier));
112 + }
113 +
114 + /**
115 + * Checks the operation of updateFlowClassifier() method.
116 + */
117 + @Test
118 + public void testUpdateFlowClassifier() {
119 + // create a flow classifier
120 + testCreateFlowClassifier();
121 +
122 + // new updates
123 + final String name2 = "FlowClassifier2";
124 + final String description2 = "FlowClassifier2";
125 + final String ethType2 = "IPv6";
126 + final String protocol2 = "tcp";
127 + final TenantId tenantId2 = TenantId.tenantId("10");
128 + final VirtualPortId virtualSrcPort2 = VirtualPortId.portId("300");
129 + final VirtualPortId virtualDstPort2 = VirtualPortId.portId("400");
130 + flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
131 + .setTenantId(tenantId2).setName(name2).setDescription(description2).setEtherType(ethType2)
132 + .setProtocol(protocol2).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
133 + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
134 + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2).build();
135 + assertThat(flowClassifierMgr.updateFlowClassifier(flowClassifier), is(true));
136 + }
137 +
138 + /**
139 + * Checks the operation of removeFlowClassifier() method.
140 + */
141 + @Test
142 + public void testRemoveFlowClassifier() {
143 + testCreateFlowClassifier();
144 + assertThat(flowClassifierMgr.removeFlowClassifier(flowClassifierId), is(true));
145 + }
146 +}