f7f24aa1de9071969dc187e79fb39cf9a07c0421
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / tablefeatures / WildcardsTablePropertySerializer.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.serialization.multipart.tablefeatures;
10
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MatchField;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Wildcards;
22
23 public class WildcardsTablePropertySerializer extends AbstractTablePropertySerializer<Wildcards> implements
24         SerializerRegistryInjector {
25
26     private SerializerRegistry registry;
27
28     @Override
29     protected void serializeProperty(final Wildcards property, final ByteBuf byteBuf) {
30         property
31             .getWildcardSetfield()
32             .getSetFieldMatch()
33             .forEach(setFieldMatch -> Preconditions.checkNotNull(registry)
34                 .<MatchField, OFSerializer<SetFieldMatch>>getSerializer(
35                     new MessageTypeKey<>(
36                         EncodeConstants.OF13_VERSION_ID,
37                         setFieldMatch.getMatchType()))
38                 .serialize(setFieldMatch, byteBuf));
39     }
40
41     @Override
42     protected TableFeaturesPropType getType() {
43         return TableFeaturesPropType.OFPTFPTWILDCARDS;
44     }
45
46     @Override
47     protected Class<Wildcards> getClazz() {
48         return Wildcards.class;
49     }
50
51     @Override
52     public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
53         registry = serializerRegistry;
54     }
55
56 }