2 * Copyright (c) 2017 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.openflowplugin.impl.protocol.deserialization.multipart;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import java.util.Optional;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
60 public class TableFeaturesMatchFieldDeserializerTest {
61 private TableFeaturesMatchFieldDeserializer deserializer = new TableFeaturesMatchFieldDeserializer();
64 public void deserialize() throws Exception {
65 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
67 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
68 Optional<SetFieldMatch> fieldMatch = deserializer.deserialize(buffer);
69 assertEquals(ArpOp.class, fieldMatch.get().getKey().getMatchType());
71 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SHA);
72 fieldMatch = deserializer.deserialize(buffer);
73 assertEquals(ArpSha.class, fieldMatch.get().getKey().getMatchType());
75 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SPA);
76 fieldMatch = deserializer.deserialize(buffer);
77 assertEquals(ArpSpa.class, fieldMatch.get().getKey().getMatchType());
79 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_THA);
80 fieldMatch = deserializer.deserialize(buffer);
81 assertEquals(ArpTha.class, fieldMatch.get().getKey().getMatchType());
83 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_TPA);
84 fieldMatch = deserializer.deserialize(buffer);
85 assertEquals(ArpTpa.class, fieldMatch.get().getKey().getMatchType());
87 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_DST);
88 fieldMatch = deserializer.deserialize(buffer);
89 assertEquals(EthDst.class, fieldMatch.get().getKey().getMatchType());
91 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_SRC);
92 fieldMatch = deserializer.deserialize(buffer);
93 assertEquals(EthSrc.class, fieldMatch.get().getKey().getMatchType());
95 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_CODE);
96 fieldMatch = deserializer.deserialize(buffer);
97 assertEquals(Icmpv4Code.class, fieldMatch.get().getKey().getMatchType());
99 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_TYPE);
100 fieldMatch = deserializer.deserialize(buffer);
101 assertEquals(Icmpv4Type.class, fieldMatch.get().getKey().getMatchType());
103 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_CODE);
104 fieldMatch = deserializer.deserialize(buffer);
105 assertEquals(Icmpv6Code.class, fieldMatch.get().getKey().getMatchType());
107 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_TYPE);
108 fieldMatch = deserializer.deserialize(buffer);
109 assertEquals(Icmpv6Type.class, fieldMatch.get().getKey().getMatchType());
111 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PHY_PORT);
112 fieldMatch = deserializer.deserialize(buffer);
113 assertEquals(InPhyPort.class, fieldMatch.get().getKey().getMatchType());
115 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PORT);
116 fieldMatch = deserializer.deserialize(buffer);
117 assertEquals(InPort.class, fieldMatch.get().getKey().getMatchType());
119 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_DSCP);
120 fieldMatch = deserializer.deserialize(buffer);
121 assertEquals(IpDscp.class, fieldMatch.get().getKey().getMatchType());
123 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_ECN);
124 fieldMatch = deserializer.deserialize(buffer);
125 assertEquals(IpEcn.class, fieldMatch.get().getKey().getMatchType());
127 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_PROTO);
128 fieldMatch = deserializer.deserialize(buffer);
129 assertEquals(IpProto.class, fieldMatch.get().getKey().getMatchType());
131 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_SRC);
132 fieldMatch = deserializer.deserialize(buffer);
133 assertEquals(Ipv4Src.class, fieldMatch.get().getKey().getMatchType());
135 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_DST);
136 fieldMatch = deserializer.deserialize(buffer);
137 assertEquals(Ipv4Dst.class, fieldMatch.get().getKey().getMatchType());
139 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_SRC);
140 fieldMatch = deserializer.deserialize(buffer);
141 assertEquals(Ipv6Src.class, fieldMatch.get().getKey().getMatchType());
143 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_DST);
144 fieldMatch = deserializer.deserialize(buffer);
145 assertEquals(Ipv6Dst.class, fieldMatch.get().getKey().getMatchType());
147 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_EXTHDR);
148 fieldMatch = deserializer.deserialize(buffer);
149 assertEquals(Ipv6Exthdr.class, fieldMatch.get().getKey().getMatchType());
151 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_FLABEL);
152 fieldMatch = deserializer.deserialize(buffer);
153 assertEquals(Ipv6Flabel.class, fieldMatch.get().getKey().getMatchType());
155 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_SLL);
156 fieldMatch = deserializer.deserialize(buffer);
157 assertEquals(Ipv6NdSll.class, fieldMatch.get().getKey().getMatchType());
159 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TLL);
160 fieldMatch = deserializer.deserialize(buffer);
161 assertEquals(Ipv6NdTll.class, fieldMatch.get().getKey().getMatchType());
163 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TARGET);
164 fieldMatch = deserializer.deserialize(buffer);
165 assertEquals(Ipv6NdTarget.class, fieldMatch.get().getKey().getMatchType());
167 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.METADATA);
168 fieldMatch = deserializer.deserialize(buffer);
169 assertEquals(Metadata.class, fieldMatch.get().getKey().getMatchType());
171 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_BOS);
172 fieldMatch = deserializer.deserialize(buffer);
173 assertEquals(MplsBos.class, fieldMatch.get().getKey().getMatchType());
175 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_LABEL);
176 fieldMatch = deserializer.deserialize(buffer);
177 assertEquals(MplsLabel.class, fieldMatch.get().getKey().getMatchType());
179 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_TC);
180 fieldMatch = deserializer.deserialize(buffer);
181 assertEquals(MplsTc.class, fieldMatch.get().getKey().getMatchType());
183 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.PBB_ISID);
184 fieldMatch = deserializer.deserialize(buffer);
185 assertEquals(PbbIsid.class, fieldMatch.get().getKey().getMatchType());
187 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_SRC);
188 fieldMatch = deserializer.deserialize(buffer);
189 assertEquals(SctpSrc.class, fieldMatch.get().getKey().getMatchType());
191 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_DST);
192 fieldMatch = deserializer.deserialize(buffer);
193 assertEquals(SctpDst.class, fieldMatch.get().getKey().getMatchType());
195 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_SRC);
196 fieldMatch = deserializer.deserialize(buffer);
197 assertEquals(TcpSrc.class, fieldMatch.get().getKey().getMatchType());
199 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_DST);
200 fieldMatch = deserializer.deserialize(buffer);
201 assertEquals(TcpDst.class, fieldMatch.get().getKey().getMatchType());
203 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TUNNEL_ID);
204 fieldMatch = deserializer.deserialize(buffer);
205 assertEquals(TunnelId.class, fieldMatch.get().getKey().getMatchType());
207 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_SRC);
208 fieldMatch = deserializer.deserialize(buffer);
209 assertEquals(UdpSrc.class, fieldMatch.get().getKey().getMatchType());
211 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_DST);
212 fieldMatch = deserializer.deserialize(buffer);
213 assertEquals(UdpDst.class, fieldMatch.get().getKey().getMatchType());
215 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_PCP);
216 fieldMatch = deserializer.deserialize(buffer);
217 assertEquals(VlanPcp.class, fieldMatch.get().getKey().getMatchType());
219 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_VID);
220 fieldMatch = deserializer.deserialize(buffer);
221 assertEquals(VlanVid.class, fieldMatch.get().getKey().getMatchType());
223 assertEquals(0, buffer.readableBytes());
226 private void addValues(ByteBuf buffer, int oxmClass, int oxmField) {
228 buffer.writeShort(oxmClass);
229 buffer.writeByte(oxmField << 1);
230 buffer.writeByte(EncodeConstants.EMPTY_LENGTH);