alshabib | 86ac11c | 2014-08-14 16:14:41 -0700 | [diff] [blame] | 1 | // Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | // Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | // Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | // This library was generated by the LoxiGen Compiler. |
| 5 | // See the file LICENSE.txt which should have been included in the source distribution |
| 6 | |
| 7 | // Automatically generated by LOXI from template unit_test.java |
| 8 | // Do not modify |
| 9 | |
| 10 | package org.projectfloodlight.openflow.protocol.ver10; |
| 11 | |
| 12 | import org.projectfloodlight.openflow.protocol.*; |
| 13 | import org.projectfloodlight.openflow.protocol.action.*; |
| 14 | import org.projectfloodlight.openflow.protocol.actionid.*; |
| 15 | import org.projectfloodlight.openflow.protocol.bsntlv.*; |
| 16 | import org.projectfloodlight.openflow.protocol.errormsg.*; |
| 17 | import org.projectfloodlight.openflow.protocol.meterband.*; |
| 18 | import org.projectfloodlight.openflow.protocol.instruction.*; |
| 19 | import org.projectfloodlight.openflow.protocol.instructionid.*; |
| 20 | import org.projectfloodlight.openflow.protocol.match.*; |
| 21 | import org.projectfloodlight.openflow.protocol.oxm.*; |
| 22 | import org.projectfloodlight.openflow.protocol.queueprop.*; |
| 23 | import org.projectfloodlight.openflow.types.*; |
| 24 | import org.projectfloodlight.openflow.util.*; |
| 25 | import org.projectfloodlight.openflow.exceptions.*; |
| 26 | import static org.junit.Assert.*; |
| 27 | import org.junit.Test; |
| 28 | import org.junit.Before; |
| 29 | import org.jboss.netty.buffer.ChannelBuffer; |
| 30 | import org.jboss.netty.buffer.ChannelBuffers; |
| 31 | import org.hamcrest.CoreMatchers; |
| 32 | |
| 33 | |
| 34 | |
| 35 | public class OFPacketInVer10Test { |
| 36 | OFFactory factory; |
| 37 | |
| 38 | final static byte[] PACKET_IN_SERIALIZED = |
| 39 | new byte[] { 0x1, 0xa, 0x0, 0x15, 0x12, 0x34, 0x56, 0x78, (byte) 0xab, (byte) 0xcd, (byte) 0xef, 0x1, 0x0, 0x9, (byte) 0xff, (byte) 0xfe, 0x1, 0x0, 0x61, 0x62, 0x63 }; |
| 40 | |
| 41 | @Before |
| 42 | public void setup() { |
| 43 | factory = OFFactoryVer10.INSTANCE; |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testWrite() { |
| 48 | OFPacketIn.Builder builder = factory.buildPacketIn(); |
| 49 | builder |
| 50 | .setXid(0x12345678) |
| 51 | .setBufferId(OFBufferId.of(0xabcdef01)) |
| 52 | .setTotalLen(9) |
| 53 | .setInPort(OFPort.LOCAL) |
| 54 | .setReason(OFPacketInReason.ACTION) |
| 55 | .setData(new byte[] { 0x61, 0x62, 0x63 } );; |
| 56 | OFPacketIn packetIn = builder.build(); |
| 57 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 58 | packetIn.writeTo(bb); |
| 59 | byte[] written = new byte[bb.readableBytes()]; |
| 60 | bb.readBytes(written); |
| 61 | |
| 62 | assertThat(written, CoreMatchers.equalTo(PACKET_IN_SERIALIZED)); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void testRead() throws Exception { |
| 67 | OFPacketIn.Builder builder = factory.buildPacketIn(); |
| 68 | builder |
| 69 | .setXid(0x12345678) |
| 70 | .setBufferId(OFBufferId.of(0xabcdef01)) |
| 71 | .setTotalLen(9) |
| 72 | .setInPort(OFPort.LOCAL) |
| 73 | .setReason(OFPacketInReason.ACTION) |
| 74 | .setData(new byte[] { 0x61, 0x62, 0x63 } );; |
| 75 | OFPacketIn packetInBuilt = builder.build(); |
| 76 | |
| 77 | ChannelBuffer input = ChannelBuffers.copiedBuffer(PACKET_IN_SERIALIZED); |
| 78 | |
| 79 | // FIXME should invoke the overall reader once implemented |
| 80 | OFPacketIn packetInRead = OFPacketInVer10.READER.readFrom(input); |
| 81 | assertEquals(PACKET_IN_SERIALIZED.length, input.readerIndex()); |
| 82 | |
| 83 | assertEquals(packetInBuilt, packetInRead); |
| 84 | } |
| 85 | |
| 86 | @Test |
| 87 | public void testReadWrite() throws Exception { |
| 88 | ChannelBuffer input = ChannelBuffers.copiedBuffer(PACKET_IN_SERIALIZED); |
| 89 | |
| 90 | // FIXME should invoke the overall reader once implemented |
| 91 | OFPacketIn packetIn = OFPacketInVer10.READER.readFrom(input); |
| 92 | assertEquals(PACKET_IN_SERIALIZED.length, input.readerIndex()); |
| 93 | |
| 94 | // write message again |
| 95 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 96 | packetIn.writeTo(bb); |
| 97 | byte[] written = new byte[bb.readableBytes()]; |
| 98 | bb.readBytes(written); |
| 99 | |
| 100 | assertThat(written, CoreMatchers.equalTo(PACKET_IN_SERIALIZED)); |
| 101 | } |
| 102 | |
| 103 | } |