3 * Copyright (c) 2013 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.packet.UDP;
17 public class UDPTest {
20 public void testGetSourcePort() {
22 byte[] udpSourcePort = { 0, 118 };
23 udp.hdrFieldsMap.put("SourcePort", udpSourcePort);
24 short sourcePort = udp.getSourcePort();
25 Assert.assertTrue(sourcePort == 118);
29 public void testGetDestinationPort() {
31 byte[] udpDestinationPort = { 1, -69 };
32 udp.hdrFieldsMap.put("DestinationPort", udpDestinationPort);
33 short destinationPort = udp.getDestinationPort();
34 Assert.assertTrue(destinationPort == 443);
38 public void testGetLength() {
40 byte[] udpLength = { 0, 20 };
41 udp.hdrFieldsMap.put("Length", udpLength);
42 short length = udp.getLength();
43 Assert.assertTrue(length == 20);
47 public void testGetChecksum() {
49 byte[] udpChecksum = { 0, -56 };
50 udp.hdrFieldsMap.put("Checksum", udpChecksum);
51 short checksum = udp.getChecksum();
52 Assert.assertTrue(checksum == 200);
56 public void testSetSourcePort() {
58 short tcpSourcePort = 118;
59 udp.setSourcePort(tcpSourcePort);
60 byte[] sourcePort = udp.hdrFieldsMap.get("SourcePort");
61 Assert.assertTrue(sourcePort[0] == 0);
62 Assert.assertTrue(sourcePort[1] == 118);
67 public void testSetDestinationPort() {
69 short tcpDestinationPort = 443;
70 udp.setDestinationPort(tcpDestinationPort);
71 byte[] destinationPort = udp.hdrFieldsMap.get("DestinationPort");
72 Assert.assertTrue(destinationPort[0] == 1);
73 Assert.assertTrue(destinationPort[1] == -69);
78 public void testSetLength() {
81 udp.setLength(udpLength);
82 byte[] length = udp.hdrFieldsMap.get("Length");
83 Assert.assertTrue(length[0] == 0);
84 Assert.assertTrue(length[1] == 20);
89 public void testSetChecksum() {
91 short udpChecksum = 200;
92 udp.setChecksum(udpChecksum);
93 byte[] checksum = udp.hdrFieldsMap.get("Checksum");
94 Assert.assertTrue(checksum[0] == 0);
95 Assert.assertTrue(checksum[1] == -56);