tom | 0eb04ca | 2014-08-25 14:34:51 -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.ver13; |
| 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 java.util.List; |
| 30 | import com.google.common.collect.ImmutableList; |
| 31 | import org.jboss.netty.buffer.ChannelBuffer; |
| 32 | import org.jboss.netty.buffer.ChannelBuffers; |
| 33 | import org.hamcrest.CoreMatchers; |
| 34 | |
| 35 | |
| 36 | |
| 37 | public class OFGroupModifyVer13Test { |
| 38 | OFFactory factory; |
| 39 | |
| 40 | final static byte[] GROUP_MODIFY_SERIALIZED = |
| 41 | new byte[] { 0x4, 0xf, 0x0, 0x70, 0x12, 0x34, 0x56, 0x78, 0x0, 0x1, 0x3, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x30, 0x0, 0x1, 0x0, 0x0, 0x0, 0x5, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0x0, 0x1, 0x0, 0x0, 0x0, 0x6, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; |
| 42 | |
| 43 | @Before |
| 44 | public void setup() { |
| 45 | factory = OFFactoryVer13.INSTANCE; |
| 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void testWrite() { |
| 50 | OFGroupModify.Builder builder = factory.buildGroupModify(); |
| 51 | OFActions actions = factory.actions(); |
| 52 | builder |
| 53 | .setXid(0x12345678) |
| 54 | .setGroupType(OFGroupType.FF) |
| 55 | .setGroup(OFGroup.of(5)) |
| 56 | .setBuckets(ImmutableList.<OFBucket>of( |
| 57 | factory.buildBucket() |
| 58 | .setWeight(1) |
| 59 | .setWatchPort(OFPort.of(5)) |
| 60 | .setWatchGroup(OFGroup.ANY) |
| 61 | .setActions(ImmutableList.<OFAction>of( |
| 62 | actions.output(OFPort.of(5), 0), |
| 63 | actions.output(OFPort.of(6), 0) |
| 64 | )) |
| 65 | .build(), |
| 66 | factory.buildBucket() |
| 67 | .setWeight(1) |
| 68 | .setWatchPort(OFPort.of(6)) |
| 69 | .setWatchGroup(OFGroup.ANY) |
| 70 | .setActions(ImmutableList.<OFAction>of( |
| 71 | actions.output(OFPort.of(5), 0), |
| 72 | actions.output(OFPort.of(6), 0) |
| 73 | )) |
| 74 | .build() |
| 75 | ) |
| 76 | ) |
| 77 | .build();; |
| 78 | OFGroupModify groupModify = builder.build(); |
| 79 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 80 | groupModify.writeTo(bb); |
| 81 | byte[] written = new byte[bb.readableBytes()]; |
| 82 | bb.readBytes(written); |
| 83 | |
| 84 | assertThat(written, CoreMatchers.equalTo(GROUP_MODIFY_SERIALIZED)); |
| 85 | } |
| 86 | |
| 87 | @Test |
| 88 | public void testRead() throws Exception { |
| 89 | OFGroupModify.Builder builder = factory.buildGroupModify(); |
| 90 | OFActions actions = factory.actions(); |
| 91 | builder |
| 92 | .setXid(0x12345678) |
| 93 | .setGroupType(OFGroupType.FF) |
| 94 | .setGroup(OFGroup.of(5)) |
| 95 | .setBuckets(ImmutableList.<OFBucket>of( |
| 96 | factory.buildBucket() |
| 97 | .setWeight(1) |
| 98 | .setWatchPort(OFPort.of(5)) |
| 99 | .setWatchGroup(OFGroup.ANY) |
| 100 | .setActions(ImmutableList.<OFAction>of( |
| 101 | actions.output(OFPort.of(5), 0), |
| 102 | actions.output(OFPort.of(6), 0) |
| 103 | )) |
| 104 | .build(), |
| 105 | factory.buildBucket() |
| 106 | .setWeight(1) |
| 107 | .setWatchPort(OFPort.of(6)) |
| 108 | .setWatchGroup(OFGroup.ANY) |
| 109 | .setActions(ImmutableList.<OFAction>of( |
| 110 | actions.output(OFPort.of(5), 0), |
| 111 | actions.output(OFPort.of(6), 0) |
| 112 | )) |
| 113 | .build() |
| 114 | ) |
| 115 | ) |
| 116 | .build();; |
| 117 | OFGroupModify groupModifyBuilt = builder.build(); |
| 118 | |
| 119 | ChannelBuffer input = ChannelBuffers.copiedBuffer(GROUP_MODIFY_SERIALIZED); |
| 120 | |
| 121 | // FIXME should invoke the overall reader once implemented |
| 122 | OFGroupModify groupModifyRead = OFGroupModifyVer13.READER.readFrom(input); |
| 123 | assertEquals(GROUP_MODIFY_SERIALIZED.length, input.readerIndex()); |
| 124 | |
| 125 | assertEquals(groupModifyBuilt, groupModifyRead); |
| 126 | } |
| 127 | |
| 128 | @Test |
| 129 | public void testReadWrite() throws Exception { |
| 130 | ChannelBuffer input = ChannelBuffers.copiedBuffer(GROUP_MODIFY_SERIALIZED); |
| 131 | |
| 132 | // FIXME should invoke the overall reader once implemented |
| 133 | OFGroupModify groupModify = OFGroupModifyVer13.READER.readFrom(input); |
| 134 | assertEquals(GROUP_MODIFY_SERIALIZED.length, input.readerIndex()); |
| 135 | |
| 136 | // write message again |
| 137 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 138 | groupModify.writeTo(bb); |
| 139 | byte[] written = new byte[bb.readableBytes()]; |
| 140 | bb.readBytes(written); |
| 141 | |
| 142 | assertThat(written, CoreMatchers.equalTo(GROUP_MODIFY_SERIALIZED)); |
| 143 | } |
| 144 | |
| 145 | } |