Bug 5540 - ActionConvertor, ActionResponseConvertor
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / cases / SalToOfPushVlanActionCase.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.Optional;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.openflowplugin.api.OFConstants;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
23
24 public class SalToOfPushVlanActionCase extends ConvertorCase<PushVlanActionCase, Action, ActionConvertorData> {
25     public SalToOfPushVlanActionCase() {
26         super(PushVlanActionCase.class, true, OFConstants.OFP_VERSION_1_3);
27     }
28
29     @Nonnull
30     @Override
31     public Optional<Action> process(@Nonnull final PushVlanActionCase source, final ActionConvertorData data) {
32         PushVlanAction pushVlanAction = source.getPushVlanAction();
33
34         PushVlanCaseBuilder pushVlanCaseBuilder = new PushVlanCaseBuilder();
35         PushVlanActionBuilder pushVlanBuilder = new PushVlanActionBuilder();
36
37         if (pushVlanAction.getEthernetType() != null) {
38             pushVlanBuilder.setEthertype(new EtherType(pushVlanAction.getEthernetType()));
39         }
40
41         pushVlanCaseBuilder.setPushVlanAction(pushVlanBuilder.build());
42
43         return Optional.of(new ActionBuilder()
44                 .setActionChoice(pushVlanCaseBuilder.build())
45                 .build());
46     }
47 }