blob: 730f325399861a3e2095b2ebffe40865ddbe2758 [file] [log] [blame]
alshabib86ac11c2014-08-14 16:14:41 -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.ver10;
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 java.util.EnumSet;
30import java.util.Set;
31import com.google.common.collect.Sets;
32import java.util.List;
33import com.google.common.collect.ImmutableList;
34import org.jboss.netty.buffer.ChannelBuffer;
35import org.jboss.netty.buffer.ChannelBuffers;
36import org.hamcrest.CoreMatchers;
37
38
39
40public class OFFlowAddVer10Test {
41 OFFactory factory;
42
43 final static byte[] FLOW_ADD_SERIALIZED =
44 new byte[] { 0x1, 0xe, 0x0, 0x70, 0x12, 0x34, 0x56, 0x78, 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, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x8, (byte) 0xff, (byte) 0xfb, 0x0, 0x0, (byte) 0xff, (byte) 0xff, 0x0, 0x10, 0x0, 0x0, 0x23, 0x20, 0x0, 0x12, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, (byte) 0xff, (byte) 0xff, 0x0, 0x10, 0x0, 0x5c, 0x16, (byte) 0xc7, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0 };
45
46 @Before
47 public void setup() {
48 factory = OFFactoryVer10.INSTANCE;
49 }
50
51 @Test
52 public void testWrite() {
53 OFFlowAdd.Builder builder = factory.buildFlowAdd();
54 builder.setXid(0x12345678)
55 .setMatch(
56 factory.buildMatch()
57 .setExact(MatchField.IN_PORT, OFPort.of(3))
58 .setExact(MatchField.ETH_TYPE, EthType.IPv4)
59 .setExact(MatchField.IPV4_SRC, IPv4Address.of(0xc0a8037f))
60 .setExact(MatchField.IPV4_DST, IPv4Address.of(0xffffffff))
61 .setExact(MatchField.ETH_SRC, MacAddress.of("01:23:45:67:89:ab"))
62 .setExact(MatchField.ETH_DST, MacAddress.of("cd:ef:01:23:45:67"))
63 .build()
64 )
65 .setIdleTimeout(5)
66 .setFlags(Sets.immutableEnumSet(OFFlowModFlags.CHECK_OVERLAP))
67 .setBufferId(OFBufferId.of(0))
68 .setOutPort(OFPort.of(0)) // doesn't make that much sense, but is in the example
69 .setActions(
70 ImmutableList.of(
71 factory.actions().output(OFPort.FLOOD, 0),
72 factory.actions().niciraDecTtl(),
73 factory.actions().bsnSetTunnelDst(0)
74 )
75 );;
76 OFFlowAdd flowAdd = builder.build();
77 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
78 flowAdd.writeTo(bb);
79 byte[] written = new byte[bb.readableBytes()];
80 bb.readBytes(written);
81
82 assertThat(written, CoreMatchers.equalTo(FLOW_ADD_SERIALIZED));
83 }
84
85 @Test
86 public void testRead() throws Exception {
87 OFFlowAdd.Builder builder = factory.buildFlowAdd();
88 builder.setXid(0x12345678)
89 .setMatch(
90 factory.buildMatch()
91 .setExact(MatchField.IN_PORT, OFPort.of(3))
92 .setExact(MatchField.ETH_TYPE, EthType.IPv4)
93 .setExact(MatchField.IPV4_SRC, IPv4Address.of(0xc0a8037f))
94 .setExact(MatchField.IPV4_DST, IPv4Address.of(0xffffffff))
95 .setExact(MatchField.ETH_SRC, MacAddress.of("01:23:45:67:89:ab"))
96 .setExact(MatchField.ETH_DST, MacAddress.of("cd:ef:01:23:45:67"))
97 .build()
98 )
99 .setIdleTimeout(5)
100 .setFlags(Sets.immutableEnumSet(OFFlowModFlags.CHECK_OVERLAP))
101 .setBufferId(OFBufferId.of(0))
102 .setOutPort(OFPort.of(0)) // doesn't make that much sense, but is in the example
103 .setActions(
104 ImmutableList.of(
105 factory.actions().output(OFPort.FLOOD, 0),
106 factory.actions().niciraDecTtl(),
107 factory.actions().bsnSetTunnelDst(0)
108 )
109 );;
110 OFFlowAdd flowAddBuilt = builder.build();
111
112 ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_ADD_SERIALIZED);
113
114 // FIXME should invoke the overall reader once implemented
115 OFFlowAdd flowAddRead = OFFlowAddVer10.READER.readFrom(input);
116 assertEquals(FLOW_ADD_SERIALIZED.length, input.readerIndex());
117
118 assertEquals(flowAddBuilt, flowAddRead);
119 }
120
121 @Test
122 public void testReadWrite() throws Exception {
123 ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_ADD_SERIALIZED);
124
125 // FIXME should invoke the overall reader once implemented
126 OFFlowAdd flowAdd = OFFlowAddVer10.READER.readFrom(input);
127 assertEquals(FLOW_ADD_SERIALIZED.length, input.readerIndex());
128
129 // write message again
130 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
131 flowAdd.writeTo(bb);
132 byte[] written = new byte[bb.readableBytes()];
133 bb.readBytes(written);
134
135 assertThat(written, CoreMatchers.equalTo(FLOW_ADD_SERIALIZED));
136 }
137
138}