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