blob: 4463de811f0a6dac15cc999ffb2872ce51a5e8b2 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001// 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
10package org.projectfloodlight.openflow.protocol.ver13;
11
12import org.projectfloodlight.openflow.protocol.*;
13import org.projectfloodlight.openflow.protocol.action.*;
14import org.projectfloodlight.openflow.protocol.actionid.*;
15import org.projectfloodlight.openflow.protocol.bsntlv.*;
16import org.projectfloodlight.openflow.protocol.errormsg.*;
17import org.projectfloodlight.openflow.protocol.meterband.*;
18import org.projectfloodlight.openflow.protocol.instruction.*;
19import org.projectfloodlight.openflow.protocol.instructionid.*;
20import org.projectfloodlight.openflow.protocol.match.*;
21import org.projectfloodlight.openflow.protocol.oxm.*;
22import org.projectfloodlight.openflow.protocol.queueprop.*;
23import org.projectfloodlight.openflow.types.*;
24import org.projectfloodlight.openflow.util.*;
25import org.projectfloodlight.openflow.exceptions.*;
26import static org.junit.Assert.*;
27import org.junit.Test;
28import org.junit.Before;
29import org.jboss.netty.buffer.ChannelBuffer;
30import org.jboss.netty.buffer.ChannelBuffers;
31import org.hamcrest.CoreMatchers;
32
33
34
35public class OFPacketInVer13Test {
36 OFFactory factory;
37
38 final static byte[] PACKET_IN_SERIALIZED =
39 new byte[] { 0x4, 0xa, 0x0, 0x35, 0x12, 0x34, 0x56, 0x78, 0x0, 0x0, 0x0, 0x64, 0x42, 0x68, 0x1, 0x14, (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, 0x76, 0x54, 0x32, 0x10, 0x0, 0x1, 0x0, 0x16, (byte) 0x80, 0x0, 0x1, 0x8, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x5, (byte) 0x80, 0x0, 0x2a, 0x2, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x61, 0x62, 0x63 };
40
41 @Before
42 public void setup() {
43 factory = OFFactoryVer13.INSTANCE;
44 }
45
46 @Test
47 public void testWrite() {
48 OFPacketIn.Builder builder = factory.buildPacketIn();
49 builder
50 .setXid(0x12345678)
51 .setBufferId(OFBufferId.of(100))
52 .setTotalLen(17000)
53 .setReason(OFPacketInReason.ACTION)
54 .setTableId(TableId.of(20))
55 .setCookie(U64.parseHex("FEDCBA9876543210"))
56 .setMatch(
57 factory.buildMatchV3()
58 .setMasked(MatchField.IN_PORT, OFPort.of(4), OFPort.of(5))
59 .setExact(MatchField.ARP_OP, ArpOpcode.REQUEST)
60 .build()
61 )
62 .setData(new byte[] { 97, 98, 99 } );;
63 OFPacketIn packetIn = builder.build();
64 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
65 packetIn.writeTo(bb);
66 byte[] written = new byte[bb.readableBytes()];
67 bb.readBytes(written);
68
69 assertThat(written, CoreMatchers.equalTo(PACKET_IN_SERIALIZED));
70 }
71
72 @Test
73 public void testRead() throws Exception {
74 OFPacketIn.Builder builder = factory.buildPacketIn();
75 builder
76 .setXid(0x12345678)
77 .setBufferId(OFBufferId.of(100))
78 .setTotalLen(17000)
79 .setReason(OFPacketInReason.ACTION)
80 .setTableId(TableId.of(20))
81 .setCookie(U64.parseHex("FEDCBA9876543210"))
82 .setMatch(
83 factory.buildMatchV3()
84 .setMasked(MatchField.IN_PORT, OFPort.of(4), OFPort.of(5))
85 .setExact(MatchField.ARP_OP, ArpOpcode.REQUEST)
86 .build()
87 )
88 .setData(new byte[] { 97, 98, 99 } );;
89 OFPacketIn packetInBuilt = builder.build();
90
91 ChannelBuffer input = ChannelBuffers.copiedBuffer(PACKET_IN_SERIALIZED);
92
93 // FIXME should invoke the overall reader once implemented
94 OFPacketIn packetInRead = OFPacketInVer13.READER.readFrom(input);
95 assertEquals(PACKET_IN_SERIALIZED.length, input.readerIndex());
96
97 assertEquals(packetInBuilt, packetInRead);
98 }
99
100 @Test
101 public void testReadWrite() throws Exception {
102 ChannelBuffer input = ChannelBuffers.copiedBuffer(PACKET_IN_SERIALIZED);
103
104 // FIXME should invoke the overall reader once implemented
105 OFPacketIn packetIn = OFPacketInVer13.READER.readFrom(input);
106 assertEquals(PACKET_IN_SERIALIZED.length, input.readerIndex());
107
108 // write message again
109 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
110 packetIn.writeTo(bb);
111 byte[] written = new byte[bb.readableBytes()];
112 bb.readBytes(written);
113
114 assertThat(written, CoreMatchers.equalTo(PACKET_IN_SERIALIZED));
115 }
116
117}