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.serialization;
11 import com.google.common.annotations.VisibleForTesting;
12 import java.util.function.Consumer;
13 import java.util.function.Function;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.ArpOpMatchFieldSerializer;
19 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.ArpShaMatchFieldSerializer;
20 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.ArpSpaMatchFieldSerializer;
21 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.ArpThaMatchFieldSerializer;
22 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.ArpTpaMatchFieldSerializer;
23 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.EthDstMatchFieldSerializer;
24 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.EthSrcMatchFieldSerializer;
25 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.EthTypeMatchFieldSerializer;
26 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Icmpv4CodeMatchFieldSerializer;
27 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Icmpv4TypeMatchFieldSerializer;
28 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Icmpv6CodeMatchFieldSerializer;
29 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Icmpv6TypeMatchFieldSerializer;
30 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.InPhyPortMatchFieldSerializer;
31 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.InPortMatchFieldSerializer;
32 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.IpDscpMatchFieldSerializer;
33 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.IpEcnMatchFieldSerializer;
34 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.IpProtoMatchFieldSerializer;
35 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv4DstMatchFieldSerializer;
36 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv4SrcMatchFieldSerializer;
37 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv6DstMatchFieldSerializer;
38 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv6ExtHdrMatchFieldSerializer;
39 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv6FlabelMatchFieldSerializer;
40 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv6NdSllMatchFieldSerializer;
41 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv6NdTargetMatchFieldSerializer;
42 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv6NdTllMatchFieldSerializer;
43 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.Ipv6SrcMatchFieldSerializer;
44 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.MetadataMatchFieldSerializer;
45 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.MplsBosMatchFieldSerializer;
46 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.MplsLabelMatchFieldSerializer;
47 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.MplsTcMatchFieldSerializer;
48 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.PbbIsidMatchFieldSerializer;
49 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.SctpDstMatchFieldSerializer;
50 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.SctpSrcMatchFieldSerializer;
51 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.TcpDstMatchFieldSerializer;
52 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.TcpFlagsMatchFieldSerializer;
53 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.TcpSrcMatchFieldSerializer;
54 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.TunnelIdMatchFieldSerializer;
55 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.UdpDstMatchFieldSerializer;
56 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.UdpSrcMatchFieldSerializer;
57 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.VlanPcpMatchFieldSerializer;
58 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.matchfield.VlanVidMatchFieldSerializer;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthType;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MatchField;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpFlags;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Src;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
106 * Util class for injecting new multipart match field serializers into OpenflowJava
108 class MultipartMatchFieldSerializerInjector {
111 * Injects multipart match field serializers into provided {@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}
112 * @param provider OpenflowJava serializer extension provider
114 static void injectSerializers(final SerializerExtensionProvider provider) {
115 // Inject new message serializers here using injector created by createInjector method
116 final Function<Class<? extends MatchField>, Consumer<OFSerializer<SetFieldMatch>>> injector =
117 createInjector(provider, EncodeConstants.OF13_VERSION_ID);
119 injector.apply(ArpOp.class).accept(new ArpOpMatchFieldSerializer());
120 injector.apply(ArpSha.class).accept(new ArpShaMatchFieldSerializer());
121 injector.apply(ArpSpa.class).accept(new ArpSpaMatchFieldSerializer());
122 injector.apply(ArpTha.class).accept(new ArpThaMatchFieldSerializer());
123 injector.apply(ArpTpa.class).accept(new ArpTpaMatchFieldSerializer());
124 injector.apply(EthDst.class).accept(new EthDstMatchFieldSerializer());
125 injector.apply(EthSrc.class).accept(new EthSrcMatchFieldSerializer());
126 injector.apply(EthType.class).accept(new EthTypeMatchFieldSerializer());
127 injector.apply(Icmpv4Code.class).accept(new Icmpv4CodeMatchFieldSerializer());
128 injector.apply(Icmpv4Type.class).accept(new Icmpv4TypeMatchFieldSerializer());
129 injector.apply(Icmpv6Code.class).accept(new Icmpv6CodeMatchFieldSerializer());
130 injector.apply(Icmpv6Type.class).accept(new Icmpv6TypeMatchFieldSerializer());
131 injector.apply(InPhyPort.class).accept(new InPhyPortMatchFieldSerializer());
132 injector.apply(InPort.class).accept(new InPortMatchFieldSerializer());
133 injector.apply(IpDscp.class).accept(new IpDscpMatchFieldSerializer());
134 injector.apply(IpEcn.class).accept(new IpEcnMatchFieldSerializer());
135 injector.apply(IpProto.class).accept(new IpProtoMatchFieldSerializer());
136 injector.apply(Ipv4Dst.class).accept(new Ipv4DstMatchFieldSerializer());
137 injector.apply(Ipv4Src.class).accept(new Ipv4SrcMatchFieldSerializer());
138 injector.apply(Ipv6Dst.class).accept(new Ipv6DstMatchFieldSerializer());
139 injector.apply(Ipv6Exthdr.class).accept(new Ipv6ExtHdrMatchFieldSerializer());
140 injector.apply(Ipv6Flabel.class).accept(new Ipv6FlabelMatchFieldSerializer());
141 injector.apply(Ipv6NdSll.class).accept(new Ipv6NdSllMatchFieldSerializer());
142 injector.apply(Ipv6NdTarget.class).accept(new Ipv6NdTargetMatchFieldSerializer());
143 injector.apply(Ipv6NdTll.class).accept(new Ipv6NdTllMatchFieldSerializer());
144 injector.apply(Ipv6Src.class).accept(new Ipv6SrcMatchFieldSerializer());
145 injector.apply(Metadata.class).accept(new MetadataMatchFieldSerializer());
146 injector.apply(MplsBos.class).accept(new MplsBosMatchFieldSerializer());
147 injector.apply(MplsLabel.class).accept(new MplsLabelMatchFieldSerializer());
148 injector.apply(MplsTc.class).accept(new MplsTcMatchFieldSerializer());
149 injector.apply(PbbIsid.class).accept(new PbbIsidMatchFieldSerializer());
150 injector.apply(SctpDst.class).accept(new SctpDstMatchFieldSerializer());
151 injector.apply(SctpSrc.class).accept(new SctpSrcMatchFieldSerializer());
152 injector.apply(TcpDst.class).accept(new TcpDstMatchFieldSerializer());
153 injector.apply(TcpFlags.class).accept(new TcpFlagsMatchFieldSerializer());
154 injector.apply(TcpSrc.class).accept(new TcpSrcMatchFieldSerializer());
155 injector.apply(TunnelId.class).accept(new TunnelIdMatchFieldSerializer());
156 // TODO: Finish implementation of Tunnel Ipv4 src and dst
157 injector.apply(TunnelIpv4Dst.class).accept(new Ipv4DstMatchFieldSerializer());
158 injector.apply(TunnelIpv4Src.class).accept(new Ipv4SrcMatchFieldSerializer());
159 injector.apply(UdpDst.class).accept(new UdpDstMatchFieldSerializer());
160 injector.apply(UdpSrc.class).accept(new UdpSrcMatchFieldSerializer());
161 injector.apply(VlanPcp.class).accept(new VlanPcpMatchFieldSerializer());
162 injector.apply(VlanVid.class).accept(new VlanVidMatchFieldSerializer());
166 * Create injector that will inject new multipart match field features serializers into #{@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}
167 * @param provider OpenflowJava serializer extension provider
168 * @param version Openflow version
172 static Function<Class<? extends MatchField>, Consumer<OFSerializer<SetFieldMatch>>> createInjector(
173 final SerializerExtensionProvider provider,
174 final byte version) {
175 return type -> serializer ->
176 provider.registerSerializer(
177 new MessageTypeKey<>(version, type),