Synchronize Flow and Group Remove events
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / flow / cases / WriteActionsCase.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.flow.cases;
10
11 import java.util.Collections;
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.ConvertorExecutor;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions;
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.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
25
26 public class WriteActionsCase extends ConvertorCase<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026
27         .instruction.instruction.WriteActionsCase, Instruction, ActionConvertorData> {
28     public WriteActionsCase() {
29         super(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction
30                 .WriteActionsCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3);
31     }
32
33     @Override
34     public Optional<Instruction> process(final @Nonnull org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types
35             .rev131026.instruction.instruction.WriteActionsCase source, final ActionConvertorData data,
36             ConvertorExecutor convertorExecutor) {
37         WriteActions writeActions = source.getWriteActions();
38         WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder();
39         WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder();
40
41         final Optional<List<Action>> actions = convertorExecutor.convert(writeActions.getAction(), data);
42
43         writeActionsBuilder.setAction(actions.orElse(Collections.emptyList()));
44         writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
45         InstructionBuilder instructionBuilder = new InstructionBuilder();
46         instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build());
47         return Optional.of(instructionBuilder.build());
48     }
49 }