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.openflowplugin.api.OFConstants;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder;
30 import org.osgi.framework.BundleContext;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class OutputTestCommandProvider implements CommandProvider {
36 private PacketProcessingService packetProcessingService;
37 private ProviderContext pc;
38 private final BundleContext ctx;
39 private boolean sessionInitiated = false;
40 private static Logger LOG = LoggerFactory.getLogger(OutputTestCommandProvider.class);
42 public OutputTestCommandProvider(final BundleContext ctx) {
46 public void onSessionInitiated(final ProviderContext session) {
48 packetProcessingService = session.getRpcService(PacketProcessingService.class);
49 ctx.registerService(CommandProvider.class.getName(), this, null);
50 this.sessionInitiated = true;
53 public void _sendOutputMsg(final CommandInterpreter ci) {
54 /* Sending package OUT */
55 LOG.debug("SendOutMsg");
56 if (sessionInitiated) {
57 String inNodeKey = ci.nextArgument();
59 // String resultOfPingFlow =
60 // OutputTestUtil.makePingFlowForNode(inNodeKey, pc);
61 // ci.println(resultOfPingFlow);
63 TransmitPacketInput input = OutputTestUtil.buildTransmitInputPacket(inNodeKey, new String(
64 "sendOutputMsg_TEST").getBytes(), "0xfffffffd", // port
67 packetProcessingService.transmitPacket(input);
69 ci.println("Session not initiated, try again in a few seconds");
73 public void _sendPacketOutputMsg(final CommandInterpreter ci) {
74 /* Sending package OUT with action */
75 LOG.debug("SendOutMsgWithAction");
76 if (sessionInitiated) {
77 String inNodeKey = ci.nextArgument();
78 String inPort = ci.nextArgument();
79 String outPort = "0xfffffffd";
81 ArrayList<Byte> _arrayList = new ArrayList<Byte>(40);
82 ArrayList<Byte> list = _arrayList;
83 String _string = new String("sendOutputMsg_TEST");
84 byte[] msg = _string.getBytes();
86 for (final byte b : msg) {
88 list.add(Byte.valueOf(b));
89 boolean _lessThan = (index < 7);
91 int _plus = (index + 1);
98 boolean _lessThan = (index < 8);
99 boolean _while = _lessThan;
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(Integer.valueOf(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(OFConstants.OFP_NO_BUFFER);
144 packetProcessingService.transmitPacket(packet_out.build());
146 ci.println("Session not initiated, try again in a few seconds");
150 public void _sendOutTopologyMsg(final 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();