2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.vpnservice.mdsalutil;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
33 public enum InstructionType {
36 public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
37 List<ActionInfo> mkActions = instructionInfo.getActionInfos();
38 List<Action> listAction = new ArrayList <Action> ();
39 for(ActionInfo mkAction: mkActions) {
40 ActionType actionType = mkAction.getActionType();
41 listAction.add(actionType.buildAction(mkAction));
43 ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
44 ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
45 InstructionBuilder instructionBuilder = new InstructionBuilder();
47 instructionBuilder.setInstruction(applyActionsCase);
48 instructionBuilder.setKey(new InstructionKey(instructionKey));
50 return instructionBuilder.build();
56 public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
57 short tableId = (short) instructionInfo.getInstructionValues()[0];
59 return new InstructionBuilder()
61 new GoToTableCaseBuilder().setGoToTable(
62 new GoToTableBuilder().setTableId(Short.valueOf(tableId)).build()).build())
63 .setKey(new InstructionKey(instructionKey)).build();
69 public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
70 List<ActionInfo> mkActions = instructionInfo.getActionInfos();
71 List<Action> listAction = new ArrayList <Action> ();
72 for(ActionInfo mkAction: mkActions) {
73 ActionType actionType = mkAction.getActionType();
74 listAction.add(actionType.buildAction(mkAction));
76 WriteActions writeActions = new WriteActionsBuilder().setAction(listAction).build();
77 WriteActionsCase writeActionsCase = new WriteActionsCaseBuilder().setWriteActions(writeActions).build();
78 InstructionBuilder instructionBuilder = new InstructionBuilder();
80 instructionBuilder.setInstruction(writeActionsCase);
81 instructionBuilder.setKey(new InstructionKey(instructionKey));
83 return instructionBuilder.build();
89 public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
91 ClearActionsCase clearActionsCase = new ClearActionsCaseBuilder().build();
93 InstructionBuilder instructionBuilder = new InstructionBuilder();
94 instructionBuilder.setInstruction(clearActionsCase);
95 instructionBuilder.setKey(new InstructionKey(instructionKey));
97 return instructionBuilder.build();
103 public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
104 BigInteger[] metadataValues = instructionInfo.getBigInstructionValues();
105 BigInteger metadata = metadataValues[0];
106 BigInteger mask = metadataValues[1];
108 return new InstructionBuilder()
110 new WriteMetadataCaseBuilder().setWriteMetadata(
111 new WriteMetadataBuilder().setMetadata(metadata).setMetadataMask(mask).build())
112 .build()).setKey(new InstructionKey(instructionKey)).build();
116 public abstract Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey);