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.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.Set; |
| 30 | import com.google.common.collect.ImmutableSet; |
| 31 | import java.util.List; |
| 32 | import com.google.common.collect.ImmutableList; |
| 33 | import org.jboss.netty.buffer.ChannelBuffer; |
| 34 | import org.jboss.netty.buffer.ChannelBuffers; |
| 35 | import org.hamcrest.CoreMatchers; |
| 36 | |
| 37 | |
| 38 | |
| 39 | public class OFFlowModifyStrictVer13Test { |
| 40 | OFFactory factory; |
| 41 | |
| 42 | final static byte[] FLOW_MODIFY_STRICT_SERIALIZED = |
| 43 | new byte[] { 0x4, 0xe, 0x0, (byte) 0x80, 0x12, 0x34, 0x56, 0x78, (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, 0x76, 0x54, 0x32, 0x10, (byte) 0xff, 0x0, (byte) 0xff, 0x0, (byte) 0xff, 0x0, (byte) 0xff, 0x0, 0x3, 0x2, 0x0, 0x5, 0x0, 0xa, 0x17, 0x70, 0x0, 0x0, 0x0, 0x32, 0x0, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x3f, (byte) 0x80, 0x0, 0x1, 0x8, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x5, (byte) 0x80, 0x0, 0xa, 0x2, (byte) 0x86, (byte) 0xdd, (byte) 0x80, 0x0, 0x14, 0x1, 0x6, (byte) 0x80, 0x0, 0x35, 0x20, 0x1c, (byte) 0xca, (byte) 0xfe, 0x1c, (byte) 0xb1, 0x10, 0x1c, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xf0, (byte) 0xff, (byte) 0xff, 0x1c, 0x2c, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x8, 0x4, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x8, 0x7, 0x0, 0x0, 0x0 }; |
| 44 | |
| 45 | @Before |
| 46 | public void setup() { |
| 47 | factory = OFFactoryVer13.INSTANCE; |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void testWrite() { |
| 52 | OFFlowModifyStrict.Builder builder = factory.buildFlowModifyStrict(); |
| 53 | builder.setXid(0x12345678) |
| 54 | .setCookie(U64.parseHex("FEDCBA9876543210")) |
| 55 | .setCookieMask(U64.parseHex("FF00FF00FF00FF00")) |
| 56 | .setTableId(TableId.of(3)) |
| 57 | .setIdleTimeout(5) |
| 58 | .setHardTimeout(10) |
| 59 | .setPriority(6000) |
| 60 | .setBufferId(OFBufferId.of(50)) |
| 61 | .setOutPort(OFPort.of(6)) |
| 62 | .setOutGroup(OFGroup.of(8)) |
| 63 | .setFlags(ImmutableSet.<OFFlowModFlags>of()) |
| 64 | .setMatch( |
| 65 | factory.buildMatch() |
| 66 | .setMasked(MatchField.IN_PORT, OFPort.of(4), OFPort.of(5)) |
| 67 | .setExact(MatchField.ETH_TYPE, EthType.IPv6) |
| 68 | .setExact(MatchField.IP_PROTO, IpProtocol.TCP) |
| 69 | .setMasked(MatchField.IPV6_SRC, |
| 70 | IPv6Address.of(0x1CCAFE1CB1101C00l, 0x0028000000000000l), |
| 71 | IPv6Address.of(0xFFFFFFFFFFF0FFFFl, 0x1C2C3C0000000000l)) |
| 72 | .build() |
| 73 | ) |
| 74 | .setInstructions( |
| 75 | ImmutableList.<OFInstruction>of( |
| 76 | factory.instructions().gotoTable(TableId.of(4)), |
| 77 | factory.instructions().gotoTable(TableId.of(7)) |
| 78 | ) |
| 79 | );; |
| 80 | OFFlowModifyStrict flowModifyStrict = builder.build(); |
| 81 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 82 | flowModifyStrict.writeTo(bb); |
| 83 | byte[] written = new byte[bb.readableBytes()]; |
| 84 | bb.readBytes(written); |
| 85 | |
| 86 | assertThat(written, CoreMatchers.equalTo(FLOW_MODIFY_STRICT_SERIALIZED)); |
| 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testRead() throws Exception { |
| 91 | OFFlowModifyStrict.Builder builder = factory.buildFlowModifyStrict(); |
| 92 | builder.setXid(0x12345678) |
| 93 | .setCookie(U64.parseHex("FEDCBA9876543210")) |
| 94 | .setCookieMask(U64.parseHex("FF00FF00FF00FF00")) |
| 95 | .setTableId(TableId.of(3)) |
| 96 | .setIdleTimeout(5) |
| 97 | .setHardTimeout(10) |
| 98 | .setPriority(6000) |
| 99 | .setBufferId(OFBufferId.of(50)) |
| 100 | .setOutPort(OFPort.of(6)) |
| 101 | .setOutGroup(OFGroup.of(8)) |
| 102 | .setFlags(ImmutableSet.<OFFlowModFlags>of()) |
| 103 | .setMatch( |
| 104 | factory.buildMatch() |
| 105 | .setMasked(MatchField.IN_PORT, OFPort.of(4), OFPort.of(5)) |
| 106 | .setExact(MatchField.ETH_TYPE, EthType.IPv6) |
| 107 | .setExact(MatchField.IP_PROTO, IpProtocol.TCP) |
| 108 | .setMasked(MatchField.IPV6_SRC, |
| 109 | IPv6Address.of(0x1CCAFE1CB1101C00l, 0x0028000000000000l), |
| 110 | IPv6Address.of(0xFFFFFFFFFFF0FFFFl, 0x1C2C3C0000000000l)) |
| 111 | .build() |
| 112 | ) |
| 113 | .setInstructions( |
| 114 | ImmutableList.<OFInstruction>of( |
| 115 | factory.instructions().gotoTable(TableId.of(4)), |
| 116 | factory.instructions().gotoTable(TableId.of(7)) |
| 117 | ) |
| 118 | );; |
| 119 | OFFlowModifyStrict flowModifyStrictBuilt = builder.build(); |
| 120 | |
| 121 | ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_MODIFY_STRICT_SERIALIZED); |
| 122 | |
| 123 | // FIXME should invoke the overall reader once implemented |
| 124 | OFFlowModifyStrict flowModifyStrictRead = OFFlowModifyStrictVer13.READER.readFrom(input); |
| 125 | assertEquals(FLOW_MODIFY_STRICT_SERIALIZED.length, input.readerIndex()); |
| 126 | |
| 127 | assertEquals(flowModifyStrictBuilt, flowModifyStrictRead); |
| 128 | } |
| 129 | |
| 130 | @Test |
| 131 | public void testReadWrite() throws Exception { |
| 132 | ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_MODIFY_STRICT_SERIALIZED); |
| 133 | |
| 134 | // FIXME should invoke the overall reader once implemented |
| 135 | OFFlowModifyStrict flowModifyStrict = OFFlowModifyStrictVer13.READER.readFrom(input); |
| 136 | assertEquals(FLOW_MODIFY_STRICT_SERIALIZED.length, input.readerIndex()); |
| 137 | |
| 138 | // write message again |
| 139 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 140 | flowModifyStrict.writeTo(bb); |
| 141 | byte[] written = new byte[bb.readableBytes()]; |
| 142 | bb.readBytes(written); |
| 143 | |
| 144 | assertThat(written, CoreMatchers.equalTo(FLOW_MODIFY_STRICT_SERIALIZED)); |
| 145 | } |
| 146 | |
| 147 | } |