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;
16 public class UDPTest {
19 public void testGetSourcePort() {
21 byte[] udpSourcePort = { 0, 118 };
22 udp.hdrFieldsMap.put("SourcePort", udpSourcePort);
23 short sourcePort = udp.getSourcePort();
24 Assert.assertTrue(sourcePort == 118);
28 public void testGetDestinationPort() {
30 byte[] udpDestinationPort = { 1, -69 };
31 udp.hdrFieldsMap.put("DestinationPort", udpDestinationPort);
32 short destinationPort = udp.getDestinationPort();
33 Assert.assertTrue(destinationPort == 443);
37 public void testGetLength() {
39 byte[] udpLength = { 0, 20 };
40 udp.hdrFieldsMap.put("Length", udpLength);
41 short length = udp.getLength();
42 Assert.assertTrue(length == 20);
46 public void testGetChecksum() {
48 byte[] udpChecksum = { 0, -56 };
49 udp.hdrFieldsMap.put("Checksum", udpChecksum);
50 short checksum = udp.getChecksum();
51 Assert.assertTrue(checksum == 200);
55 public void testSetSourcePort() {
57 short tcpSourcePort = 118;
58 udp.setSourcePort(tcpSourcePort);
59 byte[] sourcePort = udp.hdrFieldsMap.get("SourcePort");
60 Assert.assertTrue(sourcePort[0] == 0);
61 Assert.assertTrue(sourcePort[1] == 118);
66 public void testSetDestinationPort() {
68 short tcpDestinationPort = 443;
69 udp.setDestinationPort(tcpDestinationPort);
70 byte[] destinationPort = udp.hdrFieldsMap.get("DestinationPort");
71 Assert.assertTrue(destinationPort[0] == 1);
72 Assert.assertTrue(destinationPort[1] == -69);
77 public void testSetLength() {
80 udp.setLength(udpLength);
81 byte[] length = udp.hdrFieldsMap.get("Length");
82 Assert.assertTrue(length[0] == 0);
83 Assert.assertTrue(length[1] == 20);
88 public void testSetChecksum() {
90 short udpChecksum = 200;
91 udp.setChecksum(udpChecksum);
92 byte[] checksum = udp.hdrFieldsMap.get("Checksum");
93 Assert.assertTrue(checksum[0] == 0);
94 Assert.assertTrue(checksum[1] == -56);