Bug 5540 - ActionConvertor, ActionResponseConvertor
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / cases / SalToOfSetVlanPcpActionCase.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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Optional;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.openflowplugin.api.OFConstants;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpAction;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
26
27 public class SalToOfSetVlanPcpActionCase extends ConvertorCase<SetVlanPcpActionCase, Action, ActionConvertorData> {
28     public SalToOfSetVlanPcpActionCase() {
29         super(SetVlanPcpActionCase.class, true, OFConstants.OFP_VERSION_1_3);
30     }
31
32     @Nonnull
33     @Override
34     public Optional<Action> process(@Nonnull final SetVlanPcpActionCase source, final ActionConvertorData data) {
35         SetVlanPcpAction setvlanpcpaction = source.getSetVlanPcpAction();
36         SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
37         SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder();
38
39         List<MatchEntry> matchEntriesList = new ArrayList<>();
40         matchEntriesList.add(MatchConvertorUtil.toOfVlanPcp(setvlanpcpaction.getVlanPcp()));
41         setFieldBuilder.setMatchEntry(matchEntriesList);
42         setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build());
43
44         return Optional.of(new ActionBuilder()
45                 .setActionChoice(setFieldCaseBuilder.build())
46                 .build());
47     }
48 }