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;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
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.flow.InstructionsBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
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.list.Instruction;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
31 public class SimpleDropFirewallCli {
33 private SimpleDropFirewall service;
35 public void setService(SimpleDropFirewall service) {
36 this.service = service;
42 * node name node-connector number source ip-address destinatinon ip-address
45 * Parsed input from CLI
48 public AddFlowInput createTcpFlow(List<String> cliInput) {
49 AddFlowInputBuilder ret = new AddFlowInputBuilder();
50 ret.setNode(nodeFromString(cliInput.get(0)));
52 // We construct a match
53 MatchBuilder match = new MatchBuilder();
55 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
57 ipv4Match.setIpv4Source(new Ipv4Prefix(cliInput.get(3)));
58 ipv4Match.setIpv4Destination(new Ipv4Prefix(cliInput.get(4)));
60 match.setLayer3Match(ipv4Match.build());
62 match.setLayer4Match(new TcpMatchBuilder().build());
64 ret.setMatch(match.build());
66 DropActionCase dropAction = new DropActionCaseBuilder().build();
68 ActionBuilder action = new ActionBuilder();
69 action.setAction(dropAction);
71 List<Action> actions = Collections.singletonList(action.build());
73 ApplyActionsCaseBuilder aaBldr = new ApplyActionsCaseBuilder();
74 aaBldr.setApplyActions(new ApplyActionsBuilder().setAction(actions).build());
76 InstructionBuilder instructionBldr = new InstructionBuilder();
77 instructionBldr.setInstruction(aaBldr.build());
79 List<Instruction> isntructions = Collections.singletonList(instructionBldr.build());
80 InstructionsBuilder instructionsBldr = new InstructionsBuilder();
81 instructionsBldr.setInstruction(isntructions);
83 ret.setInstructions(instructionsBldr.build());
88 private NodeRef nodeFromString(String string) {
89 // TODO Auto-generated method stub