blob: 75cb4bef36a2447ca6dd39f4e69d83185f0578ae [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 org.junit.Test;
28import org.junit.Before;
29import java.util.Set;
30import com.google.common.collect.ImmutableSet;
31import java.util.List;
32import com.google.common.collect.ImmutableList;
33import org.jboss.netty.buffer.ChannelBuffer;
34import org.jboss.netty.buffer.ChannelBuffers;
35import org.hamcrest.CoreMatchers;
36
37
38
39public class OFFlowModifyVer13Test {
40 OFFactory factory;
41
42 final static byte[] FLOW_MODIFY_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, 0x1, 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 OFFlowModify.Builder builder = factory.buildFlowModify();
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 OFFlowModify flowModify = builder.build();
81 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
82 flowModify.writeTo(bb);
83 byte[] written = new byte[bb.readableBytes()];
84 bb.readBytes(written);
85
86 assertThat(written, CoreMatchers.equalTo(FLOW_MODIFY_SERIALIZED));
87 }
88
89 @Test
90 public void testRead() throws Exception {
91 OFFlowModify.Builder builder = factory.buildFlowModify();
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 OFFlowModify flowModifyBuilt = builder.build();
120
121 ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_MODIFY_SERIALIZED);
122
123 // FIXME should invoke the overall reader once implemented
124 OFFlowModify flowModifyRead = OFFlowModifyVer13.READER.readFrom(input);
125 assertEquals(FLOW_MODIFY_SERIALIZED.length, input.readerIndex());
126
127 assertEquals(flowModifyBuilt, flowModifyRead);
128 }
129
130 @Test
131 public void testReadWrite() throws Exception {
132 ChannelBuffer input = ChannelBuffers.copiedBuffer(FLOW_MODIFY_SERIALIZED);
133
134 // FIXME should invoke the overall reader once implemented
135 OFFlowModify flowModify = OFFlowModifyVer13.READER.readFrom(input);
136 assertEquals(FLOW_MODIFY_SERIALIZED.length, input.readerIndex());
137
138 // write message again
139 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
140 flowModify.writeTo(bb);
141 byte[] written = new byte[bb.readableBytes()];
142 bb.readBytes(written);
143
144 assertThat(written, CoreMatchers.equalTo(FLOW_MODIFY_SERIALIZED));
145 }
146
147}