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
8 package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
10 import static org.junit.Assert.assertEquals;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.UnpooledByteBufAllocator;
14 import java.util.Optional;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
59 public class TableFeaturesMatchFieldDeserializerTest {
60 private final TableFeaturesMatchFieldDeserializer deserializer = new TableFeaturesMatchFieldDeserializer();
63 public void deserialize() {
64 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
66 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
67 Optional<SetFieldMatch> fieldMatch = deserializer.deserialize(buffer);
68 assertEquals(ArpOp.VALUE, fieldMatch.orElseThrow().key().getMatchType());
70 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SHA);
71 fieldMatch = deserializer.deserialize(buffer);
72 assertEquals(ArpSha.VALUE, fieldMatch.orElseThrow().key().getMatchType());
74 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SPA);
75 fieldMatch = deserializer.deserialize(buffer);
76 assertEquals(ArpSpa.VALUE, fieldMatch.orElseThrow().key().getMatchType());
78 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_THA);
79 fieldMatch = deserializer.deserialize(buffer);
80 assertEquals(ArpTha.VALUE, fieldMatch.orElseThrow().key().getMatchType());
82 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_TPA);
83 fieldMatch = deserializer.deserialize(buffer);
84 assertEquals(ArpTpa.VALUE, fieldMatch.orElseThrow().key().getMatchType());
86 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_DST);
87 fieldMatch = deserializer.deserialize(buffer);
88 assertEquals(EthDst.VALUE, fieldMatch.orElseThrow().key().getMatchType());
90 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_SRC);
91 fieldMatch = deserializer.deserialize(buffer);
92 assertEquals(EthSrc.VALUE, fieldMatch.orElseThrow().key().getMatchType());
94 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_CODE);
95 fieldMatch = deserializer.deserialize(buffer);
96 assertEquals(Icmpv4Code.VALUE, fieldMatch.orElseThrow().key().getMatchType());
98 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_TYPE);
99 fieldMatch = deserializer.deserialize(buffer);
100 assertEquals(Icmpv4Type.VALUE, fieldMatch.orElseThrow().key().getMatchType());
102 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_CODE);
103 fieldMatch = deserializer.deserialize(buffer);
104 assertEquals(Icmpv6Code.VALUE, fieldMatch.orElseThrow().key().getMatchType());
106 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_TYPE);
107 fieldMatch = deserializer.deserialize(buffer);
108 assertEquals(Icmpv6Type.VALUE, fieldMatch.orElseThrow().key().getMatchType());
110 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PHY_PORT);
111 fieldMatch = deserializer.deserialize(buffer);
112 assertEquals(InPhyPort.VALUE, fieldMatch.orElseThrow().key().getMatchType());
114 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PORT);
115 fieldMatch = deserializer.deserialize(buffer);
116 assertEquals(InPort.VALUE, fieldMatch.orElseThrow().key().getMatchType());
118 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_DSCP);
119 fieldMatch = deserializer.deserialize(buffer);
120 assertEquals(IpDscp.VALUE, fieldMatch.orElseThrow().key().getMatchType());
122 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_ECN);
123 fieldMatch = deserializer.deserialize(buffer);
124 assertEquals(IpEcn.VALUE, fieldMatch.orElseThrow().key().getMatchType());
126 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_PROTO);
127 fieldMatch = deserializer.deserialize(buffer);
128 assertEquals(IpProto.VALUE, fieldMatch.orElseThrow().key().getMatchType());
130 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_SRC);
131 fieldMatch = deserializer.deserialize(buffer);
132 assertEquals(Ipv4Src.VALUE, fieldMatch.orElseThrow().key().getMatchType());
134 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_DST);
135 fieldMatch = deserializer.deserialize(buffer);
136 assertEquals(Ipv4Dst.VALUE, fieldMatch.orElseThrow().key().getMatchType());
138 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_SRC);
139 fieldMatch = deserializer.deserialize(buffer);
140 assertEquals(Ipv6Src.VALUE, fieldMatch.orElseThrow().key().getMatchType());
142 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_DST);
143 fieldMatch = deserializer.deserialize(buffer);
144 assertEquals(Ipv6Dst.VALUE, fieldMatch.orElseThrow().key().getMatchType());
146 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_EXTHDR);
147 fieldMatch = deserializer.deserialize(buffer);
148 assertEquals(Ipv6Exthdr.VALUE, fieldMatch.orElseThrow().key().getMatchType());
150 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_FLABEL);
151 fieldMatch = deserializer.deserialize(buffer);
152 assertEquals(Ipv6Flabel.VALUE, fieldMatch.orElseThrow().key().getMatchType());
154 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_SLL);
155 fieldMatch = deserializer.deserialize(buffer);
156 assertEquals(Ipv6NdSll.VALUE, fieldMatch.orElseThrow().key().getMatchType());
158 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TLL);
159 fieldMatch = deserializer.deserialize(buffer);
160 assertEquals(Ipv6NdTll.VALUE, fieldMatch.orElseThrow().key().getMatchType());
162 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TARGET);
163 fieldMatch = deserializer.deserialize(buffer);
164 assertEquals(Ipv6NdTarget.VALUE, fieldMatch.orElseThrow().key().getMatchType());
166 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.METADATA);
167 fieldMatch = deserializer.deserialize(buffer);
168 assertEquals(Metadata.VALUE, fieldMatch.orElseThrow().key().getMatchType());
170 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_BOS);
171 fieldMatch = deserializer.deserialize(buffer);
172 assertEquals(MplsBos.VALUE, fieldMatch.orElseThrow().key().getMatchType());
174 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_LABEL);
175 fieldMatch = deserializer.deserialize(buffer);
176 assertEquals(MplsLabel.VALUE, fieldMatch.orElseThrow().key().getMatchType());
178 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_TC);
179 fieldMatch = deserializer.deserialize(buffer);
180 assertEquals(MplsTc.VALUE, fieldMatch.orElseThrow().key().getMatchType());
182 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.PBB_ISID);
183 fieldMatch = deserializer.deserialize(buffer);
184 assertEquals(PbbIsid.VALUE, fieldMatch.orElseThrow().key().getMatchType());
186 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_SRC);
187 fieldMatch = deserializer.deserialize(buffer);
188 assertEquals(SctpSrc.VALUE, fieldMatch.orElseThrow().key().getMatchType());
190 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_DST);
191 fieldMatch = deserializer.deserialize(buffer);
192 assertEquals(SctpDst.VALUE, fieldMatch.orElseThrow().key().getMatchType());
194 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_SRC);
195 fieldMatch = deserializer.deserialize(buffer);
196 assertEquals(TcpSrc.VALUE, fieldMatch.orElseThrow().key().getMatchType());
198 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_DST);
199 fieldMatch = deserializer.deserialize(buffer);
200 assertEquals(TcpDst.VALUE, fieldMatch.orElseThrow().key().getMatchType());
202 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TUNNEL_ID);
203 fieldMatch = deserializer.deserialize(buffer);
204 assertEquals(TunnelId.VALUE, fieldMatch.orElseThrow().key().getMatchType());
206 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_SRC);
207 fieldMatch = deserializer.deserialize(buffer);
208 assertEquals(UdpSrc.VALUE, fieldMatch.orElseThrow().key().getMatchType());
210 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_DST);
211 fieldMatch = deserializer.deserialize(buffer);
212 assertEquals(UdpDst.VALUE, fieldMatch.orElseThrow().key().getMatchType());
214 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_PCP);
215 fieldMatch = deserializer.deserialize(buffer);
216 assertEquals(VlanPcp.VALUE, fieldMatch.orElseThrow().key().getMatchType());
218 addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_VID);
219 fieldMatch = deserializer.deserialize(buffer);
220 assertEquals(VlanVid.VALUE, fieldMatch.orElseThrow().key().getMatchType());
222 assertEquals(0, buffer.readableBytes());
225 private static void addValues(final ByteBuf buffer, final int oxmClass, final int oxmField) {
227 buffer.writeShort(oxmClass);
228 buffer.writeByte(oxmField << 1);
229 buffer.writeByte(EncodeConstants.EMPTY_LENGTH);