use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput in project openflowplugin by opendaylight.
the class PacketProcessingServiceImplTest method testTransmitPacket.
@Test
public void testTransmitPacket() throws Exception {
TransmitPacketInput transmitPacketInput = buildTransmitPacketInput();
packetProcessingService.transmitPacket(transmitPacketInput);
verify(mockedRequestContextStack).createRequestContext();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput in project openflowplugin by opendaylight.
the class PacketProcessingServiceImpl method buildRequest.
@Override
protected OfHeader buildRequest(final Xid xid, final TransmitPacketInput input) throws ServiceException {
final PacketOutConvertorData data = new PacketOutConvertorData(getVersion());
data.setDatapathId(getDatapathId());
data.setXid(xid.getValue());
final Optional<PacketOutInput> result = convertorExecutor.convert(input, data);
return result.orElse(PacketOutConvertor.defaultResult(getVersion()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput in project openflowplugin by opendaylight.
the class PacketOutConvertorTest method toPacketOutInputAllParmTest.
/**
* Test for PacketOutConvertor.
*/
@Test
public void toPacketOutInputAllParmTest() {
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder ab = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
OutputActionBuilder output = new OutputActionBuilder();
output.setMaxLength(OFConstants.OFPCML_NO_BUFFER);
Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
output.setOutputNodeConnector(value);
ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
ab.setOrder(0);
ab.setKey(new ActionKey(0));
List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList = new ArrayList<>();
actionList.add(ab.build());
Long bufferId = 0xfL;
Long valueForCookie = 0xeL;
ConnectionCookie connCook = new ConnectionCookie(valueForCookie);
String nodeId = "node:1";
NodeRef ref = createNodeRef(nodeId);
String portO = "0xfffffffd";
NodeConnectorKey egrConKey = PacketOutConvertorTest.createNodeConnKey(nodeId, portO);
NodeConnectorRef egressConfRef = new NodeConnectorRef(createNodeConnRef(nodeId, egrConKey));
String inPort = "2";
NodeConnectorKey ingrConKey = PacketOutConvertorTest.createNodeConnKey(nodeId, inPort);
NodeConnectorRef ingressConRef = new NodeConnectorRef(createNodeConnRef(nodeId, ingrConKey));
String string = new String("sendOutputMsg_TEST");
byte[] msg = string.getBytes();
byte[] payload = msg;
TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder();
transmitPacketInputBuilder.setAction(actionList);
transmitPacketInputBuilder.setBufferId(bufferId);
transmitPacketInputBuilder.setConnectionCookie(connCook);
transmitPacketInputBuilder.setEgress(egressConfRef);
transmitPacketInputBuilder.setIngress(ingressConRef);
transmitPacketInputBuilder.setNode(ref);
transmitPacketInputBuilder.setPayload(payload);
final TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.build();
Short version = (short) 0x04;
byte[] datapathIdByte = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
for (int i = 0; i < datapathIdByte.length; i++) {
datapathIdByte[i] = 1;
}
BigInteger datapathId = new BigInteger(1, datapathIdByte);
Long xid = 0xfffffL;
PacketOutConvertorData data = new PacketOutConvertorData(version);
data.setXid(xid);
data.setDatapathId(datapathId);
PacketOutInput message = convert(transmitPacketInput, data);
Assert.assertEquals(transmitPacketInput.getBufferId(), message.getBufferId());
Assert.assertEquals(Long.valueOf(inPort), message.getInPort().getValue());
Assert.assertEquals(version, message.getVersion());
Assert.assertEquals(xid, message.getXid());
ActionConvertorData actionConvertorData = new ActionConvertorData(version);
actionConvertorData.setDatapathId(datapathId);
Optional<List<Action>> actionsOptional = convertorManager.convert(actionList, actionConvertorData);
List<Action> actions = actionsOptional.orElse(Collections.emptyList());
Assert.assertEquals(actions, message.getAction());
Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput in project openflowplugin by opendaylight.
the class PacketOutConvertorTest method toPacketOutInputAllParmNullTest.
/**
* Test for {@link PacketOutConvertor} with null parameters.
*/
@Test
public void toPacketOutInputAllParmNullTest() {
TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder();
Long bufferId = null;
String nodeId = "0";
String port = "0";
NodeRef ref = createNodeRef(nodeId);
NodeConnectorKey nodeConnKey = PacketOutConvertorTest.createNodeConnKey(nodeId, port);
NodeConnectorRef egressConfRef = new NodeConnectorRef(createNodeConnRef(nodeId, nodeConnKey));
transmitPacketInputBuilder.setBufferId(bufferId);
transmitPacketInputBuilder.setConnectionCookie(null);
transmitPacketInputBuilder.setAction(null);
transmitPacketInputBuilder.setNode(ref);
transmitPacketInputBuilder.setPayload(null);
transmitPacketInputBuilder.setEgress(egressConfRef);
transmitPacketInputBuilder.setIngress(null);
TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.build();
Short version = (short) 0x04;
Long xid = null;
PacketOutConvertorData data = new PacketOutConvertorData(version);
PacketOutInput message = convert(transmitPacketInput, data);
// FIXME : this has to be fixed along with actions changed in openflowjava
Assert.assertEquals(buildActionForNullTransmitPacketInputAction(nodeConnKey, version), message.getAction());
Assert.assertEquals(OFConstants.OFP_NO_BUFFER, message.getBufferId());
Assert.assertEquals(new PortNumber(0xfffffffdL), message.getInPort());
Assert.assertEquals(version, message.getVersion());
Assert.assertEquals(xid, message.getXid());
Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput in project genius by opendaylight.
the class AlivenessProtocolHandlerLLDP method startMonitoringTask.
@Override
public void startMonitoringTask(MonitoringInfo monitorInfo) {
String sourceInterface;
EndpointType source = monitorInfo.getSource().getEndpointType();
if (source instanceof Interface) {
Interface intf = (Interface) source;
sourceInterface = intf.getInterfaceName();
} else {
LOG.warn("Invalid source endpoint. Could not retrieve source interface to send LLDP Packet");
return;
}
// Get Mac Address for the source interface
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState;
try {
interfaceState = getInterfaceFromOperDS(sourceInterface);
} catch (ReadFailedException e) {
LOG.error("getInterfaceFromOperDS failed for sourceInterface: {}", sourceInterface, e);
return;
}
Optional<byte[]> optSourceMac = getMacAddress(interfaceState);
if (!optSourceMac.isPresent()) {
LOG.error("Could not read mac address for the source interface {} from the Inventory. " + "LLDP packet cannot be send.", sourceInterface);
return;
}
byte[] sourceMac = optSourceMac.get();
String lowerLayerIf = interfaceState.getLowerLayerIf().get(0);
NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
long nodeId = Long.parseLong(getDpnFromNodeConnectorId(nodeConnectorId));
long portNum = Long.parseLong(getPortNoFromNodeConnectorId(nodeConnectorId));
Ethernet ethenetLLDPPacket = makeLLDPPacket(Long.toString(nodeId), portNum, sourceMac, sourceInterface);
try {
List<ActionInfo> actions = getInterfaceActions(interfaceState, portNum);
if (actions.isEmpty()) {
LOG.error("No interface actions to send packet out over interface {}", sourceInterface);
return;
}
TransmitPacketInput transmitPacketInput = MDSALUtil.getPacketOut(actions, ethenetLLDPPacket.serialize(), nodeId, MDSALUtil.getNodeConnRef(BigInteger.valueOf(nodeId), "0xfffffffd"));
addErrorLogging(packetProcessingService.transmitPacket(transmitPacketInput), LOG, "transmitPacket() failed: {}", transmitPacketInput);
} catch (InterruptedException | ExecutionException | PacketException e) {
LOG.error("Error while sending LLDP Packet", e);
}
}
Aggregations