2 * Copyright (c) 2013 Cisco Systems, Inc. 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.openflowplugin.openflow.samples.consumer;
10 import java.util.Collections;
11 import java.util.List;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
29 public class SimpleDropFirewallCli {
31 private SimpleDropFirewall service;
33 public void setService(final SimpleDropFirewall service) {
34 this.service = service;
40 * node name node-connector number source ip-address destinatinon ip-address
43 * Parsed input from CLI
46 public AddFlowInput createTcpFlow(final List<String> cliInput) {
47 AddFlowInputBuilder ret = new AddFlowInputBuilder();
48 ret.setNode(nodeFromString(cliInput.get(0)));
50 // We construct a match
51 MatchBuilder match = new MatchBuilder();
53 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
55 ipv4Match.setIpv4Source(new Ipv4Prefix(cliInput.get(3)));
56 ipv4Match.setIpv4Destination(new Ipv4Prefix(cliInput.get(4)));
58 match.setLayer3Match(ipv4Match.build());
60 match.setLayer4Match(new TcpMatchBuilder().build());
62 ret.setMatch(match.build());
64 DropActionCase dropAction = new DropActionCaseBuilder().build();
66 ActionBuilder action = new ActionBuilder();
67 action.setAction(dropAction);
69 List<Action> actions = Collections.singletonList(action.build());
71 ApplyActionsCaseBuilder aaBldr = new ApplyActionsCaseBuilder();
72 aaBldr.setApplyActions(new ApplyActionsBuilder().setAction(actions).build());
74 InstructionBuilder instructionBldr = new InstructionBuilder();
75 instructionBldr.setInstruction(aaBldr.build());
77 List<Instruction> isntructions = Collections.singletonList(instructionBldr.build());
78 InstructionsBuilder instructionsBldr = new InstructionsBuilder();
79 instructionsBldr.setInstruction(isntructions);
81 ret.setInstructions(instructionsBldr.build());
86 private NodeRef nodeFromString(final String string) {
87 // TODO Auto-generated method stub