30ccb2e35c9bebb574ac6b969a4a137639075b05
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / cases / SalToOfStripVlanActionCase.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.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder;
29
30 public class SalToOfStripVlanActionCase extends ConvertorCase<StripVlanActionCase, Action, ActionConvertorData> {
31     public SalToOfStripVlanActionCase() {
32         super(StripVlanActionCase.class, true, OFConstants.OFP_VERSION_1_3);
33     }
34
35     @Nonnull
36     @Override
37     public Optional<Action> process(@Nonnull final StripVlanActionCase source, final ActionConvertorData data) {
38         SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
39         SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder();
40         List<MatchEntry> entries = new ArrayList<>();
41         MatchEntryBuilder matchBuilder = new MatchEntryBuilder();
42         matchBuilder.setOxmClass(OpenflowBasicClass.class);
43         matchBuilder.setOxmMatchField(VlanVid.class);
44         matchBuilder.setHasMask(false);
45         VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
46         VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
47         vlanVidBuilder.setCfiBit(true);
48         vlanVidBuilder.setVlanVid(0x0000);
49         vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
50         matchBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
51         matchBuilder.setHasMask(false);
52         entries.add(matchBuilder.build());
53         setFieldBuilder.setMatchEntry(entries);
54         setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build());
55
56         return Optional.of(new ActionBuilder()
57                 .setActionChoice(setFieldCaseBuilder.build())
58                 .build());
59     }
60 }