blob: 8aadb179091ec76da1ff397a1183e2ed014fd615 [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 org.jboss.netty.buffer.ChannelBuffer;
30import org.jboss.netty.buffer.ChannelBuffers;
31import org.hamcrest.CoreMatchers;
32
33
34
35public class OFMatchV3Ver13Test {
36 OFFactory factory;
37
38 final static byte[] MATCH_V3_SERIALIZED =
39 new byte[] { 0x0, 0x1, 0x0, 0x3c, (byte) 0x80, 0x0, 0x5, 0x10, (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, 0x12, 0x14, 0x12, 0x10, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x12, 0x34, 0x56, 0x78, (byte) 0x80, 0x0, 0x8, 0x6, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, (byte) 0x80, 0x0, 0x20, 0x2, 0x0, 0x35, (byte) 0x80, 0x0, 0x36, 0x10, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x0, 0x0, 0x0, 0x0 };
40
41 @Before
42 public void setup() {
43 factory = OFFactoryVer13.INSTANCE;
44 }
45
46 @Test
47 public void testWrite() {
48 OFMatchV3.Builder builder = factory.buildMatchV3();
49 builder
50 .setMasked(MatchField.METADATA, OFMetadata.ofRaw(0xFEDCBA9812141210l), OFMetadata.ofRaw(0xFFFFFFFF12345678l))
51 .setExact(MatchField.ETH_SRC, MacAddress.of(new byte[] {1,2,3,4,5,6}))
52 .setExact(MatchField.UDP_DST, TransportPort.of(53))
53 .setExact(MatchField.IPV6_DST, IPv6Address.of(new byte[] { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
54 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12 }));
55 OFMatchV3 matchV3 = builder.build();
56 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
57 matchV3.writeTo(bb);
58 byte[] written = new byte[bb.readableBytes()];
59 bb.readBytes(written);
60
61 assertThat(written, CoreMatchers.equalTo(MATCH_V3_SERIALIZED));
62 }
63
64 @Test
65 public void testRead() throws Exception {
66 OFMatchV3.Builder builder = factory.buildMatchV3();
67 builder
68 .setMasked(MatchField.METADATA, OFMetadata.ofRaw(0xFEDCBA9812141210l), OFMetadata.ofRaw(0xFFFFFFFF12345678l))
69 .setExact(MatchField.ETH_SRC, MacAddress.of(new byte[] {1,2,3,4,5,6}))
70 .setExact(MatchField.UDP_DST, TransportPort.of(53))
71 .setExact(MatchField.IPV6_DST, IPv6Address.of(new byte[] { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
72 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12 }));
73 OFMatchV3 matchV3Built = builder.build();
74
75 ChannelBuffer input = ChannelBuffers.copiedBuffer(MATCH_V3_SERIALIZED);
76
77 // FIXME should invoke the overall reader once implemented
78 OFMatchV3 matchV3Read = OFMatchV3Ver13.READER.readFrom(input);
79 assertEquals(MATCH_V3_SERIALIZED.length, input.readerIndex());
80
81 assertEquals(matchV3Built, matchV3Read);
82 }
83
84 @Test
85 public void testReadWrite() throws Exception {
86 ChannelBuffer input = ChannelBuffers.copiedBuffer(MATCH_V3_SERIALIZED);
87
88 // FIXME should invoke the overall reader once implemented
89 OFMatchV3 matchV3 = OFMatchV3Ver13.READER.readFrom(input);
90 assertEquals(MATCH_V3_SERIALIZED.length, input.readerIndex());
91
92 // write message again
93 ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
94 matchV3.writeTo(bb);
95 byte[] written = new byte[bb.readableBytes()];
96 bb.readBytes(written);
97
98 assertThat(written, CoreMatchers.equalTo(MATCH_V3_SERIALIZED));
99 }
100
101}