+ /**
+ * Create Output Port Instruction with push vlan.
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param dpidLong Long the datapath ID of a switch/node
+ * @param port Long representing a port on a switch/node
+ * @param vlanId the vlan Id
+ * @param actionList list to actions to be added.
+ */
+ public static InstructionBuilder createPushVlanInstruction(InstructionBuilder ib,
+ Long dpidLong, Long port, VlanId vlanId, List<Action> actionList) {
+
+ NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ ActionBuilder ab = new ActionBuilder();
+
+ /* First we push vlan header */
+ PushVlanActionBuilder vlan = new PushVlanActionBuilder();
+ vlan.setEthernetType(IPV4);
+ ab.setAction(new PushVlanActionCaseBuilder().setPushVlanAction(vlan.build()).build());
+ ab.setOrder(actionList.size());
+ actionList.add(ab.build());
+
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
+ VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
+ vlanMatchBuilder.setVlanId(vlanIdBuilder.setVlanId(vlanId).setVlanIdPresent(true).build());
+ setFieldBuilder.setVlanMatch(vlanMatchBuilder.build());
+ ab = new ActionBuilder();
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setOrder(actionList.size());
+ actionList.add(ab.build());
+
+ ab = new ActionBuilder();
+ OutputActionBuilder output = new OutputActionBuilder();
+ output.setMaxLength(MAX_LENGTH_FOR_OUTPUT_INS);
+ output.setOutputNodeConnector(ncid);
+ ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
+ ab.setOrder(actionList.size());
+ actionList.add(ab.build());
+
+ return createOutputApplyAction(ib, actionList);
+ }
+
+ /**
+ * Create Output Port Instruction with Pop vlan.
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param dpidLong Long the datapath ID of a switch/node
+ * @param port Long representing a port on a switch/node
+ * @param instructions list to add the generated actions
+ */
+ public static InstructionBuilder createPopOutputPortInstructions(InstructionBuilder ib,
+ Long dpidLong, Long port ,
+ List<Instruction> instructions) {
+
+ List<Action> actionList = new ArrayList<>();
+ ActionBuilder ab = new ActionBuilder();
+
+ PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
+ ab.setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVlanActionBuilder.build()).build());
+ ab.setOrder(0);
+ actionList.add(ab.build());
+ List<Action> existingActions;
+ if(instructions != null && !instructions.isEmpty()) {
+ for (Instruction instruction : instructions) {
+ if (instruction.getInstruction() instanceof ApplyActionsCase) {
+ existingActions = (((ApplyActionsCase) instruction.getInstruction()).getApplyActions().getAction());
+ // Only include output actions
+ for (Action action : existingActions) {
+ if (action.getAction() instanceof OutputActionCase) {
+ actionList.add(action);
+ }
+ }
+ }
+ }
+ }
+
+ if (port != null) {
+ /* Create output action for this port*/
+ NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ OutputActionBuilder oab = new OutputActionBuilder();
+ oab.setOutputNodeConnector(ncid);
+ ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
+ ab.setOrder(actionList.size());
+ ab.setKey(new ActionKey(actionList.size()));
+ actionList.add(ab.build());
+ }
+ return createOutputApplyAction(ib, actionList);
+ }
+