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.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 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 OFFlowStatsEntryVer10Test { |
| 38 | OFFactory factory; |
| 39 | |
| 40 | final static byte[] FLOW_STATS_ENTRY_SERIALIZED = |
| 41 | new byte[] { 0x0, 0x68, 0x3, 0x0, 0x0, 0x30, 0x0, (byte) 0xe2, 0x0, 0x3, 0x1, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef, 0x1, 0x23, 0x45, 0x67, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, (byte) 0xc0, (byte) 0xa8, 0x3, 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x2, 0x0, 0x64, 0x0, 0x5, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, (byte) 0xe8, 0x0, 0x0, 0x0, 0x8, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x2, 0x0, 0x0 }; |
| 42 | |
| 43 | @Before |
| 44 | public void setup() { |
| 45 | factory = OFFactoryVer10.INSTANCE; |
| 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void testWrite() { |
| 50 | OFFlowStatsEntry.Builder builder = factory.buildFlowStatsEntry(); |
| 51 | builder |
| 52 | .setTableId(TableId.of(3)) |
| 53 | .setMatch( |
| 54 | factory.buildMatch() |
| 55 | .setExact(MatchField.IN_PORT, OFPort.of(3)) |
| 56 | .setExact(MatchField.ETH_TYPE, EthType.IPv4) |
| 57 | .setExact(MatchField.IPV4_SRC, IPv4Address.of(0xc0a8037f)) |
| 58 | .setExact(MatchField.IPV4_DST, IPv4Address.of(0xffffffff)) |
| 59 | .setExact(MatchField.ETH_SRC, MacAddress.of("01:23:45:67:89:ab")) |
| 60 | .setExact(MatchField.ETH_DST, MacAddress.of("cd:ef:01:23:45:67")) |
| 61 | .build() |
| 62 | ) |
| 63 | .setDurationSec(1) |
| 64 | .setDurationNsec(2) |
| 65 | .setPriority(100) |
| 66 | .setIdleTimeout(5) |
| 67 | .setHardTimeout(10) |
| 68 | .setCookie(U64.of(0x0123456789abcdefL)) |
| 69 | .setPacketCount(U64.of(10)) |
| 70 | .setByteCount(U64.of(1000)) |
| 71 | .setActions( |
| 72 | ImmutableList.<OFAction>of( |
| 73 | factory.actions().output(OFPort.of(1), 0), |
| 74 | factory.actions().output(OFPort.of(2), 0) |
| 75 | ) |
| 76 | );; |
| 77 | OFFlowStatsEntry flowStatsEntry = builder.build(); |
| 78 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 79 | flowStatsEntry.writeTo(bb); |
| 80 | byte[] written = new byte[bb.readableBytes()]; |
| 81 | bb.readBytes(written); |
| 82 | |
| 83 | assertThat(written, CoreMatchers.equalTo(FLOW_STATS_ENTRY_SERIALIZED)); |
| 84 | } |
| 85 | |
| 86 | @Test |
| 87 | public void testRead() throws Exception { |
| 88 | OFFlowStatsEntry.Builder builder = factory.buildFlowStatsEntry(); |
| 89 | builder |
| 90 | .setTableId(TableId.of(3)) |
| 91 | .setMatch( |
| 92 | factory.buildMatch() |
| 93 | .setExact(MatchField.IN_PORT, OFPort.of(3)) |
| 94 | .setExact(MatchField.ETH_TYPE, EthType.IPv4) |
| 95 | .setExact(MatchField.IPV4_SRC, IPv4Address.of(0xc0a8037f)) |
| 96 | .setExact(MatchField.IPV4_DST, IPv4Address.of(0xffffffff)) |
| 97 | .setExact(MatchField.ETH_SRC, MacAddress.of("01:23:45:67:89:ab")) |
| 98 | .setExact(MatchField.ETH_DST, MacAddress.of("cd:ef:01:23:45:67")) |
| 99 | .build() |
| 100 | ) |
| 101 | .setDurationSec(1) |
| 102 | .setDurationNsec(2) |
| 103 | .setPriority(100) |
| 104 | .setIdleTimeout(5) |
| 105 | .setHardTimeout(10) |
| 106 | .setCookie(U64.of(0x0123456789abcdefL)) |
| 107 | .setPacketCount(U64.of(10)) |
| 108 | .setByteCount(U64.of(1000)) |
| 109 | .setActions( |
| 110 | ImmutableList.<OFAction>of( |
| 111 | factory.actions().output(OFPort.of(1), 0), |
| 112 | factory.actions().output(OFPort.of(2), 0) |
| 113 | ) |
| 114 | );; |
| 115 | OFFlowStatsEntry flowStatsEntryBuilt = builder.build(); |
| 116 | |
| 117 | ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_STATS_ENTRY_SERIALIZED); |
| 118 | |
| 119 | // FIXME should invoke the overall reader once implemented |
| 120 | OFFlowStatsEntry flowStatsEntryRead = OFFlowStatsEntryVer10.READER.readFrom(input); |
| 121 | assertEquals(FLOW_STATS_ENTRY_SERIALIZED.length, input.readerIndex()); |
| 122 | |
| 123 | assertEquals(flowStatsEntryBuilt, flowStatsEntryRead); |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void testReadWrite() throws Exception { |
| 128 | ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_STATS_ENTRY_SERIALIZED); |
| 129 | |
| 130 | // FIXME should invoke the overall reader once implemented |
| 131 | OFFlowStatsEntry flowStatsEntry = OFFlowStatsEntryVer10.READER.readFrom(input); |
| 132 | assertEquals(FLOW_STATS_ENTRY_SERIALIZED.length, input.readerIndex()); |
| 133 | |
| 134 | // write message again |
| 135 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 136 | flowStatsEntry.writeTo(bb); |
| 137 | byte[] written = new byte[bb.readableBytes()]; |
| 138 | bb.readBytes(written); |
| 139 | |
| 140 | assertThat(written, CoreMatchers.equalTo(FLOW_STATS_ENTRY_SERIALIZED)); |
| 141 | } |
| 142 | |
| 143 | } |