Bug 1072 -Add OF13 pre-req for PCP match in TestCommandProvider
[openflowplugin.git] / drop-test / src / main / java / org / opendaylight / openflowplugin / outputtest / OutputTestCommandProvider.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.outputtest;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.apache.commons.lang.ArrayUtils;
14 import org.eclipse.osgi.framework.console.CommandInterpreter;
15 import org.eclipse.osgi.framework.console.CommandProvider;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder;
29 import org.osgi.framework.BundleContext;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class OutputTestCommandProvider implements CommandProvider {
34
35     private PacketProcessingService packetProcessingService;
36     private ProviderContext pc;
37     private final BundleContext ctx;
38     private boolean sessionInitiated = false;
39     private static Logger LOG = LoggerFactory.getLogger(OutputTestCommandProvider.class);
40
41     public OutputTestCommandProvider(BundleContext ctx) {
42         this.ctx = ctx;
43     }
44
45     public void onSessionInitiated(ProviderContext session) {
46         pc = session;
47         packetProcessingService = session.getRpcService(PacketProcessingService.class);
48         ctx.registerService(CommandProvider.class.getName(), this, null);
49         this.sessionInitiated = true;
50     }
51
52     public void _sendOutputMsg(CommandInterpreter ci) {
53         /* Sending package OUT */
54         LOG.debug("SendOutMsg");
55         if (sessionInitiated) {
56             String inNodeKey = ci.nextArgument();
57
58             // String resultOfPingFlow =
59             // OutputTestUtil.makePingFlowForNode(inNodeKey, pc);
60             // ci.println(resultOfPingFlow);
61
62             TransmitPacketInput input = OutputTestUtil.buildTransmitInputPacket(inNodeKey, new String(
63                     "sendOutputMsg_TEST").getBytes(), "0xfffffffd", // port
64                     "0");
65
66             packetProcessingService.transmitPacket(input);
67         } else {
68             ci.println("Session not initiated, try again in a few seconds");
69         }
70     }
71
72     public void _sendPacketOutputMsg(CommandInterpreter ci) {
73         /* Sending package OUT with action */
74         LOG.debug("SendOutMsgWithAction");
75         if (sessionInitiated) {
76             String inNodeKey = ci.nextArgument();
77             String inPort = ci.nextArgument();
78             String outPort = "0xfffffffd";
79
80             ArrayList<Byte> _arrayList = new ArrayList<Byte>(40);
81             ArrayList<Byte> list = _arrayList;
82             String _string = new String("sendOutputMsg_TEST");
83             byte[] msg = _string.getBytes();
84             int index = 0;
85             for (final byte b : msg) {
86                 {
87                     list.add(Byte.valueOf(b));
88                     boolean _lessThan = (index < 7);
89                     if (_lessThan) {
90                         int _plus = (index + 1);
91                         index = _plus;
92                     } else {
93                         index = 0;
94                     }
95                 }
96             }
97             boolean _lessThan = (index < 8);
98             boolean _while = _lessThan;
99             while (_while) {
100                 {
101                     Byte _byte = new Byte("0");
102                     list.add(_byte);
103                     int _plus = (index + 1);
104                     index = _plus;
105                 }
106                 boolean _lessThan_1 = (index < 8);
107                 _while = _lessThan_1;
108             }
109             NodeRef ref = OutputTestUtil.createNodeRef(inNodeKey);
110
111             TransmitPacketInputBuilder packet_out = new TransmitPacketInputBuilder();
112
113             NodeConnectorRef _createNodeConnRef_1 = OutputTestUtil.createNodeConnRef(inNodeKey, inPort);
114             NodeConnectorRef _nodeConnectorRef_1 = new NodeConnectorRef(_createNodeConnRef_1);
115             NodeConnectorRef nIngressConRef = _nodeConnectorRef_1;
116
117             NodeConnectorRef _createNodeConnRef_2 = OutputTestUtil.createNodeConnRef(inNodeKey, outPort);
118             NodeConnectorRef _nodeConnectorRef_2 = new NodeConnectorRef(_createNodeConnRef_2);
119             NodeConnectorRef nEngressConRef = _nodeConnectorRef_2;
120
121             final ArrayList<Byte> _converted_list = list;
122             byte[] _primitive = ArrayUtils.toPrimitive(_converted_list.toArray(new Byte[0]));
123
124             List<Action> actionList = new ArrayList<Action>();
125             ActionBuilder ab = new ActionBuilder();
126
127             OutputActionBuilder output = new OutputActionBuilder();
128             output.setMaxLength(new Integer(0xffff));
129             Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
130             output.setOutputNodeConnector(value);
131             ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
132             ab.setOrder(0);
133             ab.setKey(new ActionKey(0));
134             actionList.add(ab.build());
135
136             packet_out.setConnectionCookie(null);
137             packet_out.setAction(actionList);
138             packet_out.setPayload(_primitive);
139             packet_out.setNode(ref);
140             packet_out.setIngress(nIngressConRef);
141             packet_out.setEgress(nEngressConRef);
142             packet_out.setBufferId(new Long(0xffffffffL));
143
144             packetProcessingService.transmitPacket(packet_out.build());
145         } else {
146             ci.println("Session not initiated, try again in a few seconds");
147         }
148     }
149
150     public void _sendOutTopologyMsg(CommandInterpreter ci) {
151         /* Sending package OUT */
152         LOG.debug("SendOutTopologyMsg");
153
154     }
155
156     @Override
157     public String getHelp() {
158         StringBuilder strBuf = new StringBuilder("-------------- OUT Package ----------\n")
159                 .append(" sendOutputMsg command + nodeId as param sends empty package out \n ");
160         return strBuf.toString();
161     }
162 }