Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / cases / OfToSalOutputActionCase.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases;
9
10 import java.util.Optional;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.openflowplugin.api.OFConstants;
13 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
17 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction;
25 import org.opendaylight.yangtools.yang.common.Uint16;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 public class OfToSalOutputActionCase extends ConvertorCase<OutputActionCase, Action, ActionResponseConvertorData> {
30     private static final Logger LOG = LoggerFactory.getLogger(OfToSalOutputActionCase.class);
31
32     public OfToSalOutputActionCase() {
33         super(OutputActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3);
34     }
35
36     @Override
37     public Optional<Action> process(@NonNull final OutputActionCase source, final ActionResponseConvertorData data,
38             final ConvertorExecutor convertorExecutor) {
39         final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
40
41         OutputActionBuilder outputAction = new OutputActionBuilder();
42         OutputAction outputActionFromOF = source.getOutputAction();
43
44         if (outputActionFromOF.getPort() != null) {
45             PortNumberUni protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(ofVersion,
46                     outputActionFromOF.getPort().getValue());
47             String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort);
48             outputAction.setOutputNodeConnector(new Uri(portNumberAsString));
49         } else {
50             LOG.error("Provided action is not OF Output action, no associated port found!");
51         }
52
53         Uint16 maxLength = outputActionFromOF.getMaxLength();
54         if (maxLength != null) {
55             outputAction.setMaxLength(maxLength);
56         } else {
57             LOG.error("Provided action is not OF Output action, no associated length found!");
58         }
59
60         OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder();
61         outputActionCaseBuilder.setOutputAction(outputAction.build());
62
63         return Optional.of(outputActionCaseBuilder.build());
64     }
65 }