Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / tablefeatures / InstructionsTablePropertySerializer.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 io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowplugin.impl.protocol.serialization.util.InstructionUtil;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Instruction;
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.table.feature.prop.type.table.feature.prop.type.Instructions;
20
21 public class InstructionsTablePropertySerializer extends AbstractTablePropertySerializer<Instructions> implements
22         SerializerRegistryInjector {
23
24     private SerializerRegistry registry;
25
26     @Override
27     protected void serializeProperty(final Instructions property, final ByteBuf byteBuf) {
28         property
29                 .getInstructions()
30                 .nonnullInstruction().values()
31                 .stream()
32                 .sorted(OrderComparator.build())
33                 .map(Instruction::getInstruction)
34                 .forEach(instruction -> InstructionUtil
35                         .writeInstructionHeader(
36                                 instruction,
37                                 EncodeConstants.OF13_VERSION_ID,
38                                 registry,
39                                 byteBuf));
40     }
41
42     @Override
43     protected TableFeaturesPropType getType() {
44         return TableFeaturesPropType.OFPTFPTINSTRUCTIONS;
45     }
46
47     @Override
48     protected Class<Instructions> getClazz() {
49         return Instructions.class;
50     }
51
52     @Override
53     public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
54         registry = serializerRegistry;
55     }
56
57 }