Merge "Introducing the Modification classses"
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / packet / UDPTest.java
1
2 /*
3  * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.packet;
11
12 import junit.framework.Assert;
13
14 import org.junit.Test;
15 import org.opendaylight.controller.sal.match.Match;
16 import org.opendaylight.controller.sal.match.MatchType;
17
18 public class UDPTest {
19
20     @Test
21     public void testGetSourcePort() {
22         UDP udp = new UDP();
23         byte[] udpSourcePort = { 0, 118 };
24         udp.hdrFieldsMap.put("SourcePort", udpSourcePort);
25         short sourcePort = udp.getSourcePort();
26         Assert.assertTrue(sourcePort == 118);
27     }
28
29     @Test
30     public void testGetDestinationPort() {
31         UDP udp = new UDP();
32         byte[] udpDestinationPort = { 1, -69 };
33         udp.hdrFieldsMap.put("DestinationPort", udpDestinationPort);
34         short destinationPort = udp.getDestinationPort();
35         Assert.assertTrue(destinationPort == 443);
36     }
37
38     @Test
39     public void testGetLength() {
40         UDP udp = new UDP();
41         byte[] udpLength = { 0, 20 };
42         udp.hdrFieldsMap.put("Length", udpLength);
43         short length = udp.getLength();
44         Assert.assertTrue(length == 20);
45     }
46
47     @Test
48     public void testGetChecksum() {
49         UDP udp = new UDP();
50         byte[] udpChecksum = { 0, -56 };
51         udp.hdrFieldsMap.put("Checksum", udpChecksum);
52         short checksum = udp.getChecksum();
53         Assert.assertTrue(checksum == 200);
54     }
55
56     @Test
57     public void testSetSourcePort() {
58         UDP udp = new UDP();
59         short tcpSourcePort = 118;
60         udp.setSourcePort(tcpSourcePort);
61         byte[] sourcePort = udp.hdrFieldsMap.get("SourcePort");
62         Assert.assertTrue(sourcePort[0] == 0);
63         Assert.assertTrue(sourcePort[1] == 118);
64
65     }
66
67     @Test
68     public void testSetDestinationPort() {
69         UDP udp = new UDP();
70         short tcpDestinationPort = 443;
71         udp.setDestinationPort(tcpDestinationPort);
72         byte[] destinationPort = udp.hdrFieldsMap.get("DestinationPort");
73         Assert.assertTrue(destinationPort[0] == 1);
74         Assert.assertTrue(destinationPort[1] == -69);
75
76     }
77
78     @Test
79     public void testSetLength() {
80         UDP udp = new UDP();
81         short udpLength = 20;
82         udp.setLength(udpLength);
83         byte[] length = udp.hdrFieldsMap.get("Length");
84         Assert.assertTrue(length[0] == 0);
85         Assert.assertTrue(length[1] == 20);
86
87     }
88
89     @Test
90     public void testSetChecksum() {
91         UDP udp = new UDP();
92         short udpChecksum = 200;
93         udp.setChecksum(udpChecksum);
94         byte[] checksum = udp.hdrFieldsMap.get("Checksum");
95         Assert.assertTrue(checksum[0] == 0);
96         Assert.assertTrue(checksum[1] == -56);
97
98     }
99
100     @Test
101     public void testGetMatch() throws Exception {
102         UDP udp = new UDP();
103         short sport = (short) 33000;
104         short dport = (short) 843;
105         udp.setSourcePort(sport);
106         udp.setDestinationPort(dport);
107
108         Match match = udp.getMatch();
109
110         Assert.assertEquals(sport, (short) match.getField(MatchType.TP_SRC).getValue());
111         Assert.assertEquals(dport, (short) match.getField(MatchType.TP_DST).getValue());
112
113     }
114
115 }