Committed by
Gerrit Code Review
[ONOS-3116] DefaultFlowClassifierTest
Change-Id: Ie9bbc816b8e72c679302523b4746c5d0b82d3a0b
Showing
1 changed file
with
148 additions
and
0 deletions
apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java
0 → 100644
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; | ||
17 | + | ||
18 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
19 | +import static org.hamcrest.Matchers.is; | ||
20 | +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | ||
21 | + | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.IpPrefix; | ||
24 | +import org.onosproject.vtnrsc.TenantId; | ||
25 | +import org.onosproject.vtnrsc.DefaultFlowClassifier; | ||
26 | +import org.onosproject.vtnrsc.FlowClassifierId; | ||
27 | +import org.onosproject.vtnrsc.VirtualPortId; | ||
28 | +import org.onosproject.vtnrsc.FlowClassifier; | ||
29 | + | ||
30 | +import com.google.common.testing.EqualsTester; | ||
31 | + | ||
32 | +/** | ||
33 | + * Unit tests for DefaultFlowClassifier class. | ||
34 | + */ | ||
35 | +public class DefaultFlowClassifierTest { | ||
36 | + /** | ||
37 | + * Checks that the DefaultFlowClassifier class is immutable. | ||
38 | + */ | ||
39 | + @Test | ||
40 | + public void testImmutability() { | ||
41 | + assertThatClassIsImmutable(DefaultFlowClassifier.class); | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Checks the operation of equals() methods. | ||
46 | + */ | ||
47 | + @Test | ||
48 | + public void testEquals() { | ||
49 | + // Create same two flow classifier objects. | ||
50 | + final String name = "FlowClassifier1"; | ||
51 | + final String description = "FlowClassifier1"; | ||
52 | + final String ethType = "IPv4"; | ||
53 | + final String protocol = "tcp"; | ||
54 | + final int minSrcPortRange = 5; | ||
55 | + final int maxSrcPortRange = 10; | ||
56 | + final int minDstPortRange = 5; | ||
57 | + final int maxDstPortRange = 10; | ||
58 | + final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
59 | + final TenantId tenantId = TenantId.tenantId("1"); | ||
60 | + final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0"); | ||
61 | + final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0"); | ||
62 | + final VirtualPortId virtualSrcPort = VirtualPortId.portId("1"); | ||
63 | + final VirtualPortId virtualDstPort = VirtualPortId.portId("2"); | ||
64 | + | ||
65 | + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder(); | ||
66 | + final FlowClassifier flowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) | ||
67 | + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) | ||
68 | + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) | ||
69 | + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) | ||
70 | + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); | ||
71 | + | ||
72 | + flowClassifierBuilder = new DefaultFlowClassifier.Builder(); | ||
73 | + final FlowClassifier sameAsFlowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) | ||
74 | + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) | ||
75 | + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) | ||
76 | + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) | ||
77 | + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); | ||
78 | + | ||
79 | + // Create different classifier object. | ||
80 | + final String name2 = "FlowClassifier2"; | ||
81 | + final String description2 = "FlowClassifier2"; | ||
82 | + final String ethType2 = "IPv6"; | ||
83 | + final String protocol2 = "udp"; | ||
84 | + final int minSrcPortRange2 = 5; | ||
85 | + final int maxSrcPortRange2 = 10; | ||
86 | + final int minDstPortRange2 = 5; | ||
87 | + final int maxDstPortRange2 = 10; | ||
88 | + final FlowClassifierId flowClassifierId2 = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
89 | + final TenantId tenantId2 = TenantId.tenantId("2"); | ||
90 | + final IpPrefix srcIpPrefix2 = IpPrefix.valueOf("0.0.0.0/0"); | ||
91 | + final IpPrefix dstIpPrefix2 = IpPrefix.valueOf("10.10.10.10/0"); | ||
92 | + final VirtualPortId virtualSrcPort2 = VirtualPortId.portId("3"); | ||
93 | + final VirtualPortId virtualDstPort2 = VirtualPortId.portId("4"); | ||
94 | + | ||
95 | + DefaultFlowClassifier.Builder flowClassifierBuilder3 = new DefaultFlowClassifier.Builder(); | ||
96 | + final FlowClassifier flowClassifier2 = flowClassifierBuilder3.setFlowClassifierId(flowClassifierId2) | ||
97 | + .setTenantId(tenantId2).setName(name2).setDescription(description2).setEtherType(ethType2) | ||
98 | + .setProtocol(protocol2).setMinSrcPortRange(minSrcPortRange2).setMaxSrcPortRange(maxSrcPortRange2) | ||
99 | + .setMinDstPortRange(minDstPortRange2).setMaxDstPortRange(maxDstPortRange2).setSrcIpPrefix(srcIpPrefix2) | ||
100 | + .setDstIpPrefix(dstIpPrefix2).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2).build(); | ||
101 | + | ||
102 | + new EqualsTester().addEqualityGroup(flowClassifier1, sameAsFlowClassifier1).addEqualityGroup(flowClassifier2) | ||
103 | + .testEquals(); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Checks the construction of a DefaultFlowClassifier object. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void testConstruction() { | ||
111 | + final String name = "FlowClassifier"; | ||
112 | + final String description = "FlowClassifier"; | ||
113 | + final String ethType = "IPv4"; | ||
114 | + final String protocol = "tcp"; | ||
115 | + final int minSrcPortRange = 5; | ||
116 | + final int maxSrcPortRange = 10; | ||
117 | + final int minDstPortRange = 5; | ||
118 | + final int maxDstPortRange = 10; | ||
119 | + final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
120 | + final TenantId tenantId = TenantId.tenantId("1"); | ||
121 | + final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0"); | ||
122 | + final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0"); | ||
123 | + final VirtualPortId virtualSrcPort = VirtualPortId.portId("1"); | ||
124 | + final VirtualPortId virtualDstPort = VirtualPortId.portId("2"); | ||
125 | + | ||
126 | + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder(); | ||
127 | + final FlowClassifier flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) | ||
128 | + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) | ||
129 | + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) | ||
130 | + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) | ||
131 | + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); | ||
132 | + | ||
133 | + assertThat(flowClassifierId, is(flowClassifier.flowClassifierId())); | ||
134 | + assertThat(tenantId, is(flowClassifier.tenantId())); | ||
135 | + assertThat(name, is(flowClassifier.name())); | ||
136 | + assertThat(description, is(flowClassifier.description())); | ||
137 | + assertThat(ethType, is(flowClassifier.etherType())); | ||
138 | + assertThat(protocol, is(flowClassifier.protocol())); | ||
139 | + assertThat(minSrcPortRange, is(flowClassifier.minSrcPortRange())); | ||
140 | + assertThat(maxSrcPortRange, is(flowClassifier.maxSrcPortRange())); | ||
141 | + assertThat(minDstPortRange, is(flowClassifier.minDstPortRange())); | ||
142 | + assertThat(maxDstPortRange, is(flowClassifier.maxDstPortRange())); | ||
143 | + assertThat(srcIpPrefix, is(flowClassifier.srcIpPrefix())); | ||
144 | + assertThat(dstIpPrefix, is(flowClassifier.dstIpPrefix())); | ||
145 | + assertThat(virtualSrcPort, is(flowClassifier.srcPort())); | ||
146 | + assertThat(virtualDstPort, is(flowClassifier.dstPort())); | ||
147 | + } | ||
148 | +} |
-
Please register or login to post a comment