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.outputtest;
10 import java.util.ArrayList;
11 import java.util.List;
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;
33 public class OutputTestCommandProvider implements CommandProvider {
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);
41 public OutputTestCommandProvider(BundleContext ctx) {
45 public void onSessionInitiated(ProviderContext session) {
47 packetProcessingService = session.getRpcService(PacketProcessingService.class);
48 ctx.registerService(CommandProvider.class.getName(), this, null);
49 this.sessionInitiated = true;
52 public void _sendOutputMsg(CommandInterpreter ci) {
53 /* Sending package OUT */
54 LOG.debug("SendOutMsg");
55 if (sessionInitiated) {
56 String inNodeKey = ci.nextArgument();
58 // String resultOfPingFlow =
59 // OutputTestUtil.makePingFlowForNode(inNodeKey, pc);
60 // ci.println(resultOfPingFlow);
62 TransmitPacketInput input = OutputTestUtil.buildTransmitInputPacket(inNodeKey, new String(
63 "sendOutputMsg_TEST").getBytes(), "0xfffffffd", // port
66 packetProcessingService.transmitPacket(input);
68 ci.println("Session not initiated, try again in a few seconds");
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";
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();
85 for (final byte b : msg) {
87 list.add(Byte.valueOf(b));
88 boolean _lessThan = (index < 7);
90 int _plus = (index + 1);
97 boolean _lessThan = (index < 8);
98 boolean _while = _lessThan;
101 Byte _byte = new Byte("0");
103 int _plus = (index + 1);
106 boolean _lessThan_1 = (index < 8);
107 _while = _lessThan_1;
109 NodeRef ref = OutputTestUtil.createNodeRef(inNodeKey);
111 TransmitPacketInputBuilder packet_out = new TransmitPacketInputBuilder();
113 NodeConnectorRef _createNodeConnRef_1 = OutputTestUtil.createNodeConnRef(inNodeKey, inPort);
114 NodeConnectorRef _nodeConnectorRef_1 = new NodeConnectorRef(_createNodeConnRef_1);
115 NodeConnectorRef nIngressConRef = _nodeConnectorRef_1;
117 NodeConnectorRef _createNodeConnRef_2 = OutputTestUtil.createNodeConnRef(inNodeKey, outPort);
118 NodeConnectorRef _nodeConnectorRef_2 = new NodeConnectorRef(_createNodeConnRef_2);
119 NodeConnectorRef nEngressConRef = _nodeConnectorRef_2;
121 final ArrayList<Byte> _converted_list = list;
122 byte[] _primitive = ArrayUtils.toPrimitive(_converted_list.toArray(new Byte[0]));
124 List<Action> actionList = new ArrayList<Action>();
125 ActionBuilder ab = new ActionBuilder();
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());
133 ab.setKey(new ActionKey(0));
134 actionList.add(ab.build());
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));
144 packetProcessingService.transmitPacket(packet_out.build());
146 ci.println("Session not initiated, try again in a few seconds");
150 public void _sendOutTopologyMsg(CommandInterpreter ci) {
151 /* Sending package OUT */
152 LOG.debug("SendOutTopologyMsg");
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();