3 * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.sal.packet;
12 import junit.framework.Assert;
14 import org.junit.Test;
15 import org.opendaylight.controller.sal.match.Match;
16 import org.opendaylight.controller.sal.match.MatchType;
18 public class UDPTest {
21 public void testGetSourcePort() {
23 byte[] udpSourcePort = { 0, 118 };
24 udp.hdrFieldsMap.put("SourcePort", udpSourcePort);
25 short sourcePort = udp.getSourcePort();
26 Assert.assertTrue(sourcePort == 118);
30 public void testGetDestinationPort() {
32 byte[] udpDestinationPort = { 1, -69 };
33 udp.hdrFieldsMap.put("DestinationPort", udpDestinationPort);
34 short destinationPort = udp.getDestinationPort();
35 Assert.assertTrue(destinationPort == 443);
39 public void testGetLength() {
41 byte[] udpLength = { 0, 20 };
42 udp.hdrFieldsMap.put("Length", udpLength);
43 short length = udp.getLength();
44 Assert.assertTrue(length == 20);
48 public void testGetChecksum() {
50 byte[] udpChecksum = { 0, -56 };
51 udp.hdrFieldsMap.put("Checksum", udpChecksum);
52 short checksum = udp.getChecksum();
53 Assert.assertTrue(checksum == 200);
57 public void testSetSourcePort() {
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);
68 public void testSetDestinationPort() {
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);
79 public void testSetLength() {
82 udp.setLength(udpLength);
83 byte[] length = udp.hdrFieldsMap.get("Length");
84 Assert.assertTrue(length[0] == 0);
85 Assert.assertTrue(length[1] == 20);
90 public void testSetChecksum() {
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);
101 public void testGetMatch() throws Exception {
103 short sport = (short) 33000;
104 short dport = (short) 843;
105 udp.setSourcePort(sport);
106 udp.setDestinationPort(dport);
108 Match match = udp.getMatch();
110 Assert.assertEquals(sport, (short) match.getField(MatchType.TP_SRC).getValue());
111 Assert.assertEquals(dport, (short) match.getField(MatchType.TP_DST).getValue());