Fixed the problem with the Vlan PCP not being passed on to the switch.
[controller.git] / opendaylight / protocol_plugins / openflow / src / test / java / org / opendaylight / controller / protocol_plugin / openflow / vendorextension / v6extension / V6ExtensionTest.java
1 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
2
3 import static org.junit.Assert.fail;
4
5 import java.net.InetAddress;
6 import java.net.UnknownHostException;
7 import java.nio.ByteBuffer;
8 import java.util.Arrays;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.openflow.protocol.OFMatch;
13
14 public class V6ExtensionTest {
15
16     @Test
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();
22
23         OFMatch ofm = new OFMatch();
24         V6Match match4 = new V6Match(ofm);
25
26         match.fromString("");
27         Assert.assertTrue(match.equals(match2));
28         match.fromString("any");
29         Assert.assertTrue(match.equals(match2));
30         Assert.assertTrue(match.equals(match4));
31         try {
32             match.fromString("invalidArgument");
33
34             fail("Did not throw IllegalArgumentException");
35         } catch (IllegalArgumentException e) {
36             // passed test for throwing exception.
37         }
38         try {
39             match.fromString("invalidParameter=abcdefg");
40             fail("Did not throw IllegalArgumentException");
41         } catch (IllegalArgumentException e) {
42             // passed test for throwing exception.
43         }
44
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");
48
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");
58
59         Assert.assertTrue(match.getInputPort() == 1);
60         // Assert.assertTrue(match.getIPv6MatchLen()==6);
61
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);
68
69         addr = InetAddress.getByName("1.2.3.4");
70         int ipdst = ByteBuffer.wrap(addr.getAddress()).getInt();
71         ofm.setNetworkDestination(ipdst);
72
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);
84
85         V6Match match3 = new V6Match(ofm);
86
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());
109
110     }
111
112     @Test
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("dl_vpcp=1");
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");
128
129         ByteBuffer data = ByteBuffer.allocateDirect(10000);
130         match.writeTo(data);
131         data.flip();
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()));
139
140         Assert.assertTrue(match.getNetworkSrc().equals(match2.getNetworkSrc()));
141         Assert.assertTrue(match.getNetworkDest()
142                 .equals(match2.getNetworkDest()));
143
144         Assert.assertTrue(match.getDataLayerVirtualLan() == match2
145                 .getDataLayerVirtualLan());
146         Assert.assertTrue(match.getDataLayerVirtualLanPriorityCodePoint() == match2
147                 .getDataLayerVirtualLanPriorityCodePoint());
148         Assert.assertTrue(match.getNetworkProtocol() == match2
149                 .getNetworkProtocol());
150         Assert.assertTrue(match.getNetworkTypeOfService() == match2
151                 .getNetworkTypeOfService());
152         Assert.assertTrue(match.getTransportSource() == match2
153                 .getTransportSource());
154         Assert.assertTrue(match.getTransportDestination() == match2
155                 .getTransportDestination());
156
157     }
158
159     @Test
160     public void testClone() {
161         V6Match match = new V6Match();
162         match.fromString("input_port=1");
163         match.fromString("dl_dst=20:A0:11:10:00:99");
164         match.fromString("dl_src=00:10:08:22:12:75");
165         match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333/64");
166         match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222/64");
167         match.fromString("dl_vlan=10");
168         match.fromString("dl_vpcp=1");
169         match.fromString("nw_proto=6");
170         match.fromString("nw_tos=100");
171         match.fromString("tp_dst=8080");
172         match.fromString("tp_src=60");
173         match.fromString("dl_type=0x800");
174
175         V6Match match2 = match.clone();
176         Assert.assertTrue(match.getInputPort() == match2.getInputPort());
177         Assert.assertTrue(Arrays.equals(match.getDataLayerSource(),
178                 match2.getDataLayerSource()));
179         Assert.assertTrue(Arrays.equals(match.getDataLayerDestination(),
180                 match2.getDataLayerDestination()));
181         Assert.assertTrue(match.getNetworkSrc().equals(match2.getNetworkSrc()));
182         Assert.assertTrue(match.getNetworkDest()
183                 .equals(match2.getNetworkDest()));
184         Assert.assertTrue(match.getDataLayerVirtualLan() == match2
185                 .getDataLayerVirtualLan());
186         Assert.assertTrue(match.getDataLayerVirtualLanPriorityCodePoint() == match2
187                 .getDataLayerVirtualLanPriorityCodePoint());
188         Assert.assertTrue(match.getNetworkProtocol() == match2
189                 .getNetworkProtocol());
190         Assert.assertTrue(match.getNetworkTypeOfService() == match2
191                 .getNetworkTypeOfService());
192         Assert.assertTrue(match.getTransportSource() == match2
193                 .getTransportSource());
194         Assert.assertTrue(match.getTransportDestination() == match2
195                 .getTransportDestination());
196         Assert.assertTrue(match.getWildcards() == match2.getWildcards());
197     }
198
199     @Test
200     public void testPadding() {
201         // testing that matchlen+pad keeps the 8byte alignment
202         V6Match match = new V6Match();
203
204         match.fromString("input_port=1");
205         Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
206         match.fromString("dl_dst=20:A0:11:10:00:99");
207         match.fromString("dl_src=00:10:08:22:12:75");
208         Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
209         match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333");
210         Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
211         match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222");
212         Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
213         match.fromString("dl_vlan=10");
214         match.fromString("dl_vpcp=1");
215         match.fromString("nw_proto=6");
216         Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
217         match.fromString("nw_tos=100");
218         match.fromString("tp_dst=8080");
219         Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
220         match.fromString("tp_src=60");
221         Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0);
222     }
223 }