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