Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / TableFeaturesMatchFieldDeserializerTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
10
11 import static org.junit.Assert.assertEquals;
12
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;
59
60 public class TableFeaturesMatchFieldDeserializerTest {
61     private TableFeaturesMatchFieldDeserializer deserializer = new TableFeaturesMatchFieldDeserializer();
62
63     @Test
64     public void deserialize() throws Exception {
65         ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
66
67         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
68         Optional<SetFieldMatch> fieldMatch = deserializer.deserialize(buffer);
69         assertEquals(ArpOp.class, fieldMatch.get().key().getMatchType());
70
71         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SHA);
72         fieldMatch = deserializer.deserialize(buffer);
73         assertEquals(ArpSha.class, fieldMatch.get().key().getMatchType());
74
75         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_SPA);
76         fieldMatch = deserializer.deserialize(buffer);
77         assertEquals(ArpSpa.class, fieldMatch.get().key().getMatchType());
78
79         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_THA);
80         fieldMatch = deserializer.deserialize(buffer);
81         assertEquals(ArpTha.class, fieldMatch.get().key().getMatchType());
82
83         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_TPA);
84         fieldMatch = deserializer.deserialize(buffer);
85         assertEquals(ArpTpa.class, fieldMatch.get().key().getMatchType());
86
87         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_DST);
88         fieldMatch = deserializer.deserialize(buffer);
89         assertEquals(EthDst.class, fieldMatch.get().key().getMatchType());
90
91         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ETH_SRC);
92         fieldMatch = deserializer.deserialize(buffer);
93         assertEquals(EthSrc.class, fieldMatch.get().key().getMatchType());
94
95         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_CODE);
96         fieldMatch = deserializer.deserialize(buffer);
97         assertEquals(Icmpv4Code.class, fieldMatch.get().key().getMatchType());
98
99         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV4_TYPE);
100         fieldMatch = deserializer.deserialize(buffer);
101         assertEquals(Icmpv4Type.class, fieldMatch.get().key().getMatchType());
102
103         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_CODE);
104         fieldMatch = deserializer.deserialize(buffer);
105         assertEquals(Icmpv6Code.class, fieldMatch.get().key().getMatchType());
106
107         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ICMPV6_TYPE);
108         fieldMatch = deserializer.deserialize(buffer);
109         assertEquals(Icmpv6Type.class, fieldMatch.get().key().getMatchType());
110
111         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PHY_PORT);
112         fieldMatch = deserializer.deserialize(buffer);
113         assertEquals(InPhyPort.class, fieldMatch.get().key().getMatchType());
114
115         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IN_PORT);
116         fieldMatch = deserializer.deserialize(buffer);
117         assertEquals(InPort.class, fieldMatch.get().key().getMatchType());
118
119         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_DSCP);
120         fieldMatch = deserializer.deserialize(buffer);
121         assertEquals(IpDscp.class, fieldMatch.get().key().getMatchType());
122
123         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_ECN);
124         fieldMatch = deserializer.deserialize(buffer);
125         assertEquals(IpEcn.class, fieldMatch.get().key().getMatchType());
126
127         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IP_PROTO);
128         fieldMatch = deserializer.deserialize(buffer);
129         assertEquals(IpProto.class, fieldMatch.get().key().getMatchType());
130
131         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_SRC);
132         fieldMatch = deserializer.deserialize(buffer);
133         assertEquals(Ipv4Src.class, fieldMatch.get().key().getMatchType());
134
135         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV4_DST);
136         fieldMatch = deserializer.deserialize(buffer);
137         assertEquals(Ipv4Dst.class, fieldMatch.get().key().getMatchType());
138
139         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_SRC);
140         fieldMatch = deserializer.deserialize(buffer);
141         assertEquals(Ipv6Src.class, fieldMatch.get().key().getMatchType());
142
143         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_DST);
144         fieldMatch = deserializer.deserialize(buffer);
145         assertEquals(Ipv6Dst.class, fieldMatch.get().key().getMatchType());
146
147         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_EXTHDR);
148         fieldMatch = deserializer.deserialize(buffer);
149         assertEquals(Ipv6Exthdr.class, fieldMatch.get().key().getMatchType());
150
151         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_FLABEL);
152         fieldMatch = deserializer.deserialize(buffer);
153         assertEquals(Ipv6Flabel.class, fieldMatch.get().key().getMatchType());
154
155         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_SLL);
156         fieldMatch = deserializer.deserialize(buffer);
157         assertEquals(Ipv6NdSll.class, fieldMatch.get().key().getMatchType());
158
159         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TLL);
160         fieldMatch = deserializer.deserialize(buffer);
161         assertEquals(Ipv6NdTll.class, fieldMatch.get().key().getMatchType());
162
163         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_ND_TARGET);
164         fieldMatch = deserializer.deserialize(buffer);
165         assertEquals(Ipv6NdTarget.class, fieldMatch.get().key().getMatchType());
166
167         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.METADATA);
168         fieldMatch = deserializer.deserialize(buffer);
169         assertEquals(Metadata.class, fieldMatch.get().key().getMatchType());
170
171         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_BOS);
172         fieldMatch = deserializer.deserialize(buffer);
173         assertEquals(MplsBos.class, fieldMatch.get().key().getMatchType());
174
175         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_LABEL);
176         fieldMatch = deserializer.deserialize(buffer);
177         assertEquals(MplsLabel.class, fieldMatch.get().key().getMatchType());
178
179         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.MPLS_TC);
180         fieldMatch = deserializer.deserialize(buffer);
181         assertEquals(MplsTc.class, fieldMatch.get().key().getMatchType());
182
183         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.PBB_ISID);
184         fieldMatch = deserializer.deserialize(buffer);
185         assertEquals(PbbIsid.class, fieldMatch.get().key().getMatchType());
186
187         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_SRC);
188         fieldMatch = deserializer.deserialize(buffer);
189         assertEquals(SctpSrc.class, fieldMatch.get().key().getMatchType());
190
191         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.SCTP_DST);
192         fieldMatch = deserializer.deserialize(buffer);
193         assertEquals(SctpDst.class, fieldMatch.get().key().getMatchType());
194
195         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_SRC);
196         fieldMatch = deserializer.deserialize(buffer);
197         assertEquals(TcpSrc.class, fieldMatch.get().key().getMatchType());
198
199         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TCP_DST);
200         fieldMatch = deserializer.deserialize(buffer);
201         assertEquals(TcpDst.class, fieldMatch.get().key().getMatchType());
202
203         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TUNNEL_ID);
204         fieldMatch = deserializer.deserialize(buffer);
205         assertEquals(TunnelId.class, fieldMatch.get().key().getMatchType());
206
207         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_SRC);
208         fieldMatch = deserializer.deserialize(buffer);
209         assertEquals(UdpSrc.class, fieldMatch.get().key().getMatchType());
210
211         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.UDP_DST);
212         fieldMatch = deserializer.deserialize(buffer);
213         assertEquals(UdpDst.class, fieldMatch.get().key().getMatchType());
214
215         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_PCP);
216         fieldMatch = deserializer.deserialize(buffer);
217         assertEquals(VlanPcp.class, fieldMatch.get().key().getMatchType());
218
219         addValues(buffer, OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_VID);
220         fieldMatch = deserializer.deserialize(buffer);
221         assertEquals(VlanVid.class, fieldMatch.get().key().getMatchType());
222
223         assertEquals(0, buffer.readableBytes());
224     }
225
226     private void addValues(ByteBuf buffer, int oxmClass, int oxmField) {
227         buffer.clear();
228         buffer.writeShort(oxmClass);
229         buffer.writeByte(oxmField << 1);
230         buffer.writeByte(EncodeConstants.EMPTY_LENGTH);
231     }
232 }