2 * Copyright (c) 2013 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.openflowjava.protocol.impl.serialization.action;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
17 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.OxmFieldsAction;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
27 * @author michal.polkorab
30 public class OF13SetFieldActionSerializer implements OFSerializer<Action>,
31 HeaderSerializer<Action>, SerializerRegistryInjector {
33 private SerializerRegistry registry;
36 public void serialize(Action action, ByteBuf outBuffer) {
37 int startIndex = outBuffer.writerIndex();
38 outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);
39 int lengthIndex = outBuffer.writerIndex();
40 outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
41 OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class);
42 MatchEntry entry = oxmField.getMatchEntry().get(0);
43 MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(
44 EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField());
45 if (entry.getOxmClass().equals(ExperimenterClass.class)) {
46 ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) entry.getMatchEntryValue();
47 key.setExperimenterId(experimenterIdCase.getExperimenter().getExperimenter().getValue());
49 key.setExperimenterId(null);
51 OFSerializer<MatchEntry> serializer = registry.getSerializer(key);
52 serializer.serialize(entry, outBuffer);
53 int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING;
54 if (paddingRemainder != 0) {
55 outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
57 outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
61 public void serializeHeader(Action input, ByteBuf outBuffer) {
62 outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);
63 outBuffer.writeShort(ActionConstants.ACTION_IDS_LENGTH);
67 public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
68 registry = serializerRegistry;