1 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
3 import static org.junit.Assert.fail;
5 import java.net.InetAddress;
6 import java.net.UnknownHostException;
7 import java.nio.ByteBuffer;
8 import java.util.Arrays;
9 import org.junit.Assert;
10 import org.junit.Test;
11 import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match;
12 import org.openflow.protocol.OFMatch;
14 public class V6ExtensionTest {
17 public void testFromString() throws UnknownHostException {
18 // This tests creating V6Match using fromString and OFMatch by comparing
19 // the results to each other
20 V6Match match = new V6Match();
21 V6Match match2 = new V6Match();
23 OFMatch ofm = new OFMatch();
24 V6Match match4 = new V6Match(ofm);
27 Assert.assertTrue(match.equals(match2));
28 match.fromString("any");
29 Assert.assertTrue(match.equals(match2));
30 Assert.assertTrue(match.equals(match4));
32 match.fromString("invalidArgument");
34 fail("Did not throw IllegalArgumentException");
35 } catch (IllegalArgumentException e) {
36 // passed test for throwing exception.
39 match.fromString("invalidParameter=abcdefg");
40 fail("Did not throw IllegalArgumentException");
41 } catch (IllegalArgumentException e) {
42 // passed test for throwing exception.
45 match.fromString("input_port=1");
46 match.fromString("dl_dst=20:A0:11:10:00:99");
47 match.fromString("dl_src=00:10:08:22:12:75");
49 match.fromString("ip_src=10.1.1.1");
50 match.fromString("ip_dst=1.2.3.4");
51 match.fromString("eth_type=0x800");
52 match.fromString("dl_vlan=10");
53 match.fromString("dl_vpcp=1");
54 match.fromString("nw_proto=6");
55 match.fromString("nw_tos=100");
56 match.fromString("tp_dst=8080");
57 match.fromString("tp_src=60");
59 Assert.assertTrue(match.getInputPort() == 1);
60 // Assert.assertTrue(match.getIPv6MatchLen()==6);
62 ofm.setInputPort((short) 1);
63 // V6Match is meant for IPv6, but if using OFMatch, it will be set to
64 // IPv4 values, as OF1.0 doesn't support IPv6.
65 InetAddress addr = InetAddress.getByName("10.1.1.1");
66 int ipsrc = ByteBuffer.wrap(addr.getAddress()).getInt();
67 ofm.setNetworkSource(ipsrc);
69 addr = InetAddress.getByName("1.2.3.4");
70 int ipdst = ByteBuffer.wrap(addr.getAddress()).getInt();
71 ofm.setNetworkDestination(ipdst);
73 byte[] macSrc = { 0x00, 0x10, 0x08, 0x22, 0x12, 0x75 };
74 ofm.setDataLayerSource(macSrc);
75 byte[] macDst = { 0x20, (byte) 0xA0, 0x11, 0x10, 0x00, (byte) 0x99 };
76 ofm.setDataLayerDestination(macDst);
77 ofm.setDataLayerType((short) 0x800);
78 ofm.setDataLayerVirtualLan((short) 10);
79 ofm.setDataLayerVirtualLanPriorityCodePoint((byte) 1);
80 ofm.setNetworkProtocol((byte) 6);
81 ofm.setNetworkTypeOfService((byte) 100);
82 ofm.setTransportSource((short) 60);
83 ofm.setTransportDestination((short) 8080);
85 V6Match match3 = new V6Match(ofm);
87 Assert.assertTrue(match.getInputPort() == match3.getInputPort());
88 Assert.assertTrue(Arrays.equals(match.getDataLayerSource(),
89 match3.getDataLayerSource()));
90 Assert.assertTrue(Arrays.equals(match.getDataLayerDestination(),
91 match3.getDataLayerDestination()));
92 Assert.assertNull(match.getNetworkSrc());
93 Assert.assertNull(match3.getNetworkSrc());
94 Assert.assertNull(match.getNetworkDest());
95 Assert.assertNull(match3.getNetworkDest());
96 Assert.assertTrue(match.getDataLayerVirtualLan() == match3
97 .getDataLayerVirtualLan());
98 Assert.assertTrue(match.getDataLayerVirtualLanPriorityCodePoint() == match3
99 .getDataLayerVirtualLanPriorityCodePoint());
100 Assert.assertTrue(match.getNetworkProtocol() == match3
101 .getNetworkProtocol());
102 Assert.assertTrue(match.getNetworkTypeOfService() == match3
103 .getNetworkTypeOfService());
104 Assert.assertTrue(match.getTransportSource() == match3
105 .getTransportSource());
106 Assert.assertTrue(match.getTransportDestination() == match3
107 .getTransportDestination());
108 Assert.assertTrue(match.getWildcards() == match3.getWildcards());
113 public void testReadWriteBuffer() {
114 V6Match match = new V6Match();
115 match.fromString("input_port=1");
116 match.fromString("dl_dst=20:A0:11:10:00:99");
117 match.fromString("dl_src=00:10:08:22:12:75");
118 // writeTo(ByteBuffer) will only write IPv6
119 match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333/64");
120 match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222/64");
121 match.fromString("dl_vlan=10");
122 match.fromString("nw_proto=6");
123 match.fromString("nw_tos=100");
124 match.fromString("tp_dst=8080");
125 match.fromString("tp_src=60");
126 match.fromString("dl_type=0x800");
128 ByteBuffer data = ByteBuffer.allocateDirect(10000);
131 V6Match match2 = new V6Match();
132 match2.readFrom(data);
133 Assert.assertTrue(match.getInputPort() == match2.getInputPort());
134 Assert.assertTrue(Arrays.equals(match.getDataLayerSource(),
135 match2.getDataLayerSource()));
136 Assert.assertTrue(Arrays.equals(match.getDataLayerDestination(),
137 match2.getDataLayerDestination()));
139 Assert.assertTrue(match.getNetworkSrc().equals(match2.getNetworkSrc()));
140 Assert.assertTrue(match.getNetworkDest()
141 .equals(match2.getNetworkDest()));
143 Assert.assertTrue(match.getDataLayerVirtualLan() == match2
144 .getDataLayerVirtualLan());
145 // vlan pcp isn't part of write/read buffer
146 Assert.assertTrue(match.getNetworkProtocol() == match2
147 .getNetworkProtocol());
148 Assert.assertTrue(match.getNetworkTypeOfService() == match2
149 .getNetworkTypeOfService());
150 Assert.assertTrue(match.getTransportSource() == match2
151 .getTransportSource());
152 Assert.assertTrue(match.getTransportDestination() == match2
153 .getTransportDestination());
158 public void testClone() {
159 V6Match match = new V6Match();
160 match.fromString("input_port=1");
161 match.fromString("dl_dst=20:A0:11:10:00:99");
162 match.fromString("dl_src=00:10:08:22:12:75");
163 match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333/64");
164 match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222/64");
165 match.fromString("dl_vlan=10");
166 match.fromString("dl_vpcp=1");
167 match.fromString("nw_proto=6");
168 match.fromString("nw_tos=100");
169 match.fromString("tp_dst=8080");
170 match.fromString("tp_src=60");
171 match.fromString("dl_type=0x800");
173 V6Match match2 = match.clone();
174 Assert.assertTrue(match.getInputPort() == match2.getInputPort());
175 Assert.assertTrue(Arrays.equals(match.getDataLayerSource(),
176 match2.getDataLayerSource()));
177 Assert.assertTrue(Arrays.equals(match.getDataLayerDestination(),
178 match2.getDataLayerDestination()));
179 Assert.assertTrue(match.getNetworkSrc().equals(match2.getNetworkSrc()));
180 Assert.assertTrue(match.getNetworkDest()
181 .equals(match2.getNetworkDest()));
182 Assert.assertTrue(match.getDataLayerVirtualLan() == match2
183 .getDataLayerVirtualLan());
184 Assert.assertTrue(match.getDataLayerVirtualLanPriorityCodePoint() == match2
185 .getDataLayerVirtualLanPriorityCodePoint());
186 Assert.assertTrue(match.getNetworkProtocol() == match2
187 .getNetworkProtocol());
188 Assert.assertTrue(match.getNetworkTypeOfService() == match2
189 .getNetworkTypeOfService());
190 Assert.assertTrue(match.getTransportSource() == match2
191 .getTransportSource());
192 Assert.assertTrue(match.getTransportDestination() == match2
193 .getTransportDestination());
194 Assert.assertTrue(match.getWildcards() == match2.getWildcards());
198 public void testPadding() {
199 // testing that matchlen+pad keeps the 8byte alignment
200 V6Match match = new V6Match();
202 match.fromString("input_port=1");
203 Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
204 match.fromString("dl_dst=20:A0:11:10:00:99");
205 match.fromString("dl_src=00:10:08:22:12:75");
206 Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
207 match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333");
208 Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
209 match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222");
210 Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
211 match.fromString("dl_vlan=10");
212 match.fromString("dl_vpcp=1");
213 match.fromString("nw_proto=6");
214 Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
215 match.fromString("nw_tos=100");
216 match.fromString("tp_dst=8080");
217 Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
218 match.fromString("tp_src=60");
219 Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);