X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fadsal%2Fsal%2Fapi%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fpacket%2FTCPTest.java;fp=opendaylight%2Fadsal%2Fsal%2Fapi%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fpacket%2FTCPTest.java;h=e56f41e5c1b301cf78eb8e1e5df3f29fcbe1e7e2;hb=42c32160bfd41de57189bb246fec5ffb48ed8e9e;hp=0000000000000000000000000000000000000000;hpb=edf5bfcee83c750853253ccfd991ba7000f5f65b;p=controller.git diff --git a/opendaylight/adsal/sal/api/src/test/java/org/opendaylight/controller/sal/packet/TCPTest.java b/opendaylight/adsal/sal/api/src/test/java/org/opendaylight/controller/sal/packet/TCPTest.java new file mode 100644 index 0000000000..e56f41e5c1 --- /dev/null +++ b/opendaylight/adsal/sal/api/src/test/java/org/opendaylight/controller/sal/packet/TCPTest.java @@ -0,0 +1,132 @@ + +/* + * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.sal.packet; + +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.controller.sal.match.Match; +import org.opendaylight.controller.sal.match.MatchType; + +public class TCPTest { + + @Test + public void testSetSourcePort() { + TCP tcp = new TCP(); + short tcpSourcePort = 118; + tcp.setSourcePort(tcpSourcePort); + byte[] sourcePort = tcp.hdrFieldsMap.get(TCP.SRCPORT); + Assert.assertTrue(sourcePort[0] == 0); + Assert.assertTrue(sourcePort[1] == 118); + + } + + @Test + public void testSetDestinationPort() { + TCP tcp = new TCP(); + short tcpDestinationPort = 443; + tcp.setDestinationPort(tcpDestinationPort); + byte[] destinationPort = tcp.hdrFieldsMap.get(TCP.DESTPORT); + Assert.assertTrue(destinationPort[0] == 1); + Assert.assertTrue(destinationPort[1] == -69); + + } + + @Test + public void testSetSequenceNumber() { + TCP tcp = new TCP(); + short tcpSequenceNumber = 700; + tcp.setSequenceNumber(tcpSequenceNumber); + byte[] sequenceNumber = tcp.hdrFieldsMap.get(TCP.SEQNUMBER); + Assert.assertTrue(sequenceNumber[0] == 0); + Assert.assertTrue(sequenceNumber[1] == 0); + Assert.assertTrue(sequenceNumber[2] == 2); + Assert.assertTrue(sequenceNumber[3] == -68); + } + + @Test + public void testSetAckNumber() { + TCP tcp = new TCP(); + short tcpAckNumber = 697; + tcp.setAckNumber(tcpAckNumber); + byte[] ackNumber = tcp.hdrFieldsMap.get(TCP.ACKNUMBER); + Assert.assertTrue(ackNumber[0] == 0); + Assert.assertTrue(ackNumber[1] == 0); + Assert.assertTrue(ackNumber[2] == 2); + Assert.assertTrue(ackNumber[3] == -71); + } + + @Test + public void testSetHeaderLenFlags() { + TCP tcp = new TCP(); + short tcpFlags = 26; + tcp.setHeaderLenFlags(tcpFlags); + byte[] headerLenFlags = tcp.hdrFieldsMap.get(TCP.HEADERLENFLAGS); + Assert.assertTrue(headerLenFlags[0] == 0); + Assert.assertTrue(headerLenFlags[1] == 26); + + } + + @Test + public void testSetWindowSize() { + TCP tcp = new TCP(); + short tcpWindowSize = 100; + tcp.setWindowSize(tcpWindowSize); + byte[] windowSize = tcp.hdrFieldsMap.get(TCP.WINDOWSIZE); + Assert.assertTrue(windowSize[0] == 0); + Assert.assertTrue(windowSize[1] == 100); + + } + + @Test + public void testSetChecksum() { + TCP tcp = new TCP(); + short tcpChecksum = 134; + tcp.setChecksum(tcpChecksum); + byte[] checksum = tcp.hdrFieldsMap.get(TCP.CHECKSUM); + Assert.assertTrue(checksum[0] == 0); + Assert.assertTrue(checksum[1] == -122); + + } + + @Test + public void testSetUrgentPointer() { + TCP tcp = new TCP(); + short tcpUrgentPointer = 25098; + tcp.setUrgentPointer(tcpUrgentPointer); + byte[] urgentPointer = tcp.hdrFieldsMap.get(TCP.URGENTPOINTER); + Assert.assertTrue(urgentPointer[0] == 98); + Assert.assertTrue(urgentPointer[1] == 10); + + } + + @Test + public void testGetChecksum() { + TCP tcp = new TCP(); + byte[] udpChecksum = { 0, -56 }; + tcp.hdrFieldsMap.put("Checksum", udpChecksum); + short checksum = tcp.getChecksum(); + Assert.assertTrue(checksum == 200); + } + + @Test + public void testGetMatch() throws Exception { + TCP tcp = new TCP(); + short sport = (short) 52012; + short dport = (short) 40345; + tcp.setSourcePort(sport); + tcp.setDestinationPort(dport); + + Match match = tcp.getMatch(); + + Assert.assertEquals(sport, (short) match.getField(MatchType.TP_SRC).getValue()); + Assert.assertEquals(dport, (short) match.getField(MatchType.TP_DST).getValue()); + } +}