f3d1fee6043326b7f4e278cb89103f70277c0487
[openflowplugin.git] / samples / sample-consumer / src / main / java / org / opendaylight / openflowplugin / openflow / samples / consumer / SimpleDropFirewallCli.java
1 /**
2  * Copyright (c) 2013 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 package org.opendaylight.openflowplugin.openflow.samples.consumer;
9
10 import java.util.Collections;
11 import java.util.List;
12
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;
30
31 public class SimpleDropFirewallCli {
32
33     private SimpleDropFirewall service;
34
35     public void setService(SimpleDropFirewall service) {
36         this.service = service;
37     }
38
39     /**
40      * Form of input is:
41      * 
42      * node name node-connector number source ip-address destinatinon ip-address
43      * 
44      * @param cliInput
45      *            Parsed input from CLI
46      * @return
47      */
48     public AddFlowInput createTcpFlow(List<String> cliInput) {
49         AddFlowInputBuilder ret = new AddFlowInputBuilder();
50         ret.setNode(nodeFromString(cliInput.get(0)));
51
52         // We construct a match
53         MatchBuilder match = new MatchBuilder();
54
55         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
56
57         ipv4Match.setIpv4Source(new Ipv4Prefix(cliInput.get(3)));
58         ipv4Match.setIpv4Destination(new Ipv4Prefix(cliInput.get(4)));
59
60         match.setLayer3Match(ipv4Match.build());
61
62         match.setLayer4Match(new TcpMatchBuilder().build());
63
64         ret.setMatch(match.build());
65
66         DropActionCase dropAction = new DropActionCaseBuilder().build();
67
68         ActionBuilder action = new ActionBuilder();
69         action.setAction(dropAction);
70
71         List<Action> actions = Collections.singletonList(action.build());
72         //
73         ApplyActionsCaseBuilder aaBldr = new ApplyActionsCaseBuilder();
74         aaBldr.setApplyActions(new ApplyActionsBuilder().setAction(actions).build());
75         
76         InstructionBuilder instructionBldr = new InstructionBuilder();
77         instructionBldr.setInstruction(aaBldr.build());
78         
79         List<Instruction> isntructions = Collections.singletonList(instructionBldr.build());
80         InstructionsBuilder instructionsBldr = new InstructionsBuilder();
81                 instructionsBldr.setInstruction(isntructions);
82         
83         ret.setInstructions(instructionsBldr.build());
84
85         return ret.build();
86     }
87
88     private NodeRef nodeFromString(String string) {
89         // TODO Auto-generated method stub
90         return null;
91     }
92
93 }