2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.util;
11 import junit.framework.Assert;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.UnpooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
23 * @author michal.polkorab
26 public class OF10MatchSerializerTest {
29 * Testing correct serialization of ofp_match
33 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
34 MatchV10Builder builder = new MatchV10Builder();
35 builder.setWildcards(new FlowWildcardsV10(false, false, false, true, false,
36 false, true, false, true, true, true));
37 builder.setNwSrcMask((short) 24);
38 builder.setNwDstMask((short) 16);
39 builder.setInPort(6653);
40 builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
41 builder.setDlDst(new MacAddress("02:02:02:02:02:02"));
42 builder.setDlVlan(128);
43 builder.setDlVlanPcp((short) 2);
44 builder.setDlType(15);
45 builder.setNwTos((short) 14);
46 builder.setNwProto((short) 85);
47 builder.setNwSrc(new Ipv4Address("1.1.1.2"));
48 builder.setNwDst(new Ipv4Address("32.16.8.1"));
49 builder.setTpSrc(2048);
50 builder.setTpDst(4096);
51 MatchV10 match = builder.build();
52 OF10MatchSerializer.encodeMatchV10(out, match);
54 Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt());
55 Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
56 byte[] dlSrc = new byte[6];
58 Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
59 byte[] dlDst = new byte[6];
61 Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));
62 Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());
63 Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());
65 Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());
66 Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());
67 Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());
69 Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());
70 Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());
71 Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());
72 Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());
76 * Testing correct serialization of ofp_match
80 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
81 MatchV10Builder builder = new MatchV10Builder();
82 builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true,
83 true, true, true, true, true, true));
84 builder.setNwSrcMask((short) 0);
85 builder.setNwDstMask((short) 0);
86 builder.setInPort(6653);
87 builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
88 builder.setDlDst(new MacAddress("02:02:02:02:02:02"));
89 builder.setDlVlan(128);
90 builder.setDlVlanPcp((short) 2);
91 builder.setDlType(15);
92 builder.setNwTos((short) 14);
93 builder.setNwProto((short) 85);
94 builder.setNwSrc(new Ipv4Address("1.1.1.2"));
95 builder.setNwDst(new Ipv4Address("32.16.8.1"));
96 builder.setTpSrc(2048);
97 builder.setTpDst(4096);
98 MatchV10 match = builder.build();
99 OF10MatchSerializer.encodeMatchV10(out, match);
101 Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());
102 Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
103 byte[] dlSrc = new byte[6];
104 out.readBytes(dlSrc);
105 Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
106 byte[] dlDst = new byte[6];
107 out.readBytes(dlDst);
108 Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));
109 Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());
110 Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());
112 Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());
113 Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());
114 Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());
116 Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());
117 Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());
118 Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());
119 Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());