blob: b01a93af3e1634037a9ec82de1784ab45e277fe1 [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 java.util.Set;
28import org.junit.Test;
29import org.junit.Before;
30import org.jboss.netty.buffer.ChannelBuffer;
31import org.jboss.netty.buffer.ChannelBuffers;
32import org.hamcrest.CoreMatchers;
33
34
35
36public class OFActionSetFieldVer13TcpSrcTest {
37 OFActions factory;
38
39 final static byte[] ACTION_SET_FIELD_SERIALIZED =
40 new byte[] { 0x0, 0x19, 0x0, 0x10, (byte) 0x80, 0x0, 0x1a, 0x2, 0x0, 0x32, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
41
42 @Before
43 public void setup() {
44 factory = OFActionsVer13.INSTANCE;
45 }
46
47 @Test
48 public void testWrite() {
49 OFActionSetField.Builder builder = factory.buildSetField();
50 OFOxms oxms = OFFactories.getFactory(OFVersion.OF_13).oxms();
51builder.setField(oxms.tcpSrc(TransportPort.of(50)));
52 OFActionSetField actionSetField = builder.build();
53 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
54 actionSetField.writeTo(bb);
55 byte[] written = new byte[bb.readableBytes()];
56 bb.readBytes(written);
57
58 assertThat(written, CoreMatchers.equalTo(ACTION_SET_FIELD_SERIALIZED));
59 }
60
61 @Test
62 public void testRead() throws Exception {
63 OFActionSetField.Builder builder = factory.buildSetField();
64 OFOxms oxms = OFFactories.getFactory(OFVersion.OF_13).oxms();
65builder.setField(oxms.tcpSrc(TransportPort.of(50)));
66 OFActionSetField actionSetFieldBuilt = builder.build();
67
68 ChannelBuffer input = ChannelBuffers.copiedBuffer(ACTION_SET_FIELD_SERIALIZED);
69
70 // FIXME should invoke the overall reader once implemented
71 OFActionSetField actionSetFieldRead = OFActionSetFieldVer13.READER.readFrom(input);
72 assertEquals(ACTION_SET_FIELD_SERIALIZED.length, input.readerIndex());
73
74 assertEquals(actionSetFieldBuilt, actionSetFieldRead);
75 }
76
77 @Test
78 public void testReadWrite() throws Exception {
79 ChannelBuffer input = ChannelBuffers.copiedBuffer(ACTION_SET_FIELD_SERIALIZED);
80
81 // FIXME should invoke the overall reader once implemented
82 OFActionSetField actionSetField = OFActionSetFieldVer13.READER.readFrom(input);
83 assertEquals(ACTION_SET_FIELD_SERIALIZED.length, input.readerIndex());
84
85 // write message again
86 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
87 actionSetField.writeTo(bb);
88 byte[] written = new byte[bb.readableBytes()];
89 bb.readBytes(written);
90
91 assertThat(written, CoreMatchers.equalTo(ACTION_SET_FIELD_SERIALIZED));
92 }
93
94}