use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project controller by opendaylight.
the class RoutedBindingRTClient method runTest.
public void runTest(final int iterations) {
int rpcOk = 0;
int rpcError = 0;
int rpcServerCnt = inVal.size();
for (int i = 0; i < iterations; i++) {
RoutedRpcBenchInput input = inVal.get(ThreadLocalRandom.current().nextInt(rpcServerCnt));
Future<RpcResult<RoutedRpcBenchOutput>> output = service.routedRpcBench(input);
try {
RpcResult<RoutedRpcBenchOutput> rpcResult = output.get();
if (rpcResult.isSuccessful()) {
List<Payload> retVal = rpcResult.getResult().getPayload();
if (retVal.size() == inSize) {
rpcOk++;
} else {
rpcError++;
}
}
} catch (InterruptedException | ExecutionException e) {
rpcError++;
LOG.error("Execution failed: ", e);
}
}
this.rpcOk.addAndGet(rpcOk);
this.rpcError.addAndGet(rpcError);
}
use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project openflowplugin by opendaylight.
the class LLDPDiscoveryUtils method lldpToNodeConnectorRef.
/**
* Returns the encoded in custom TLV for the given lldp.
*
* @param payload lldp payload
* @param useExtraAuthenticatorCheck make it more secure (CVE-2015-1611 CVE-2015-1612)
* @return nodeConnectorId - encoded in custom TLV of given lldp
*/
@SuppressWarnings("checkstyle:IllegalCatch")
public static NodeConnectorRef lldpToNodeConnectorRef(byte[] payload, boolean useExtraAuthenticatorCheck) {
NodeConnectorRef nodeConnectorRef = null;
if (isLLDP(payload)) {
Ethernet ethPkt = new Ethernet();
try {
ethPkt.deserialize(payload, 0, payload.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.warn("Failed to decode LLDP packet {}", e);
return nodeConnectorRef;
}
LLDP lldp = (LLDP) ethPkt.getPayload();
try {
NodeId srcNodeId = null;
NodeConnectorId srcNodeConnectorId = null;
final LLDPTLV systemIdTLV = lldp.getSystemNameId();
if (systemIdTLV != null) {
String srcNodeIdString = new String(systemIdTLV.getValue(), Charset.defaultCharset());
srcNodeId = new NodeId(srcNodeIdString);
} else {
throw new Exception("Node id wasn't specified via systemNameId in LLDP packet.");
}
final LLDPTLV nodeConnectorIdLldptlv = lldp.getCustomTLV(LLDPTLV.createPortSubTypeCustomTLVKey());
if (nodeConnectorIdLldptlv != null) {
srcNodeConnectorId = new NodeConnectorId(LLDPTLV.getCustomString(nodeConnectorIdLldptlv.getValue(), nodeConnectorIdLldptlv.getLength()));
} else {
throw new Exception("Node connector wasn't specified via Custom TLV in LLDP packet.");
}
if (useExtraAuthenticatorCheck) {
boolean secure = checkExtraAuthenticator(lldp, srcNodeConnectorId);
if (!secure) {
LOG.warn("SECURITY ALERT: there is probably a LLDP spoofing attack in progress.");
throw new Exception("Attack. LLDP packet with inconsistent extra authenticator field was received.");
}
}
InstanceIdentifier<NodeConnector> srcInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(srcNodeId)).child(NodeConnector.class, new NodeConnectorKey(srcNodeConnectorId)).toInstance();
nodeConnectorRef = new NodeConnectorRef(srcInstanceId);
} catch (Exception e) {
LOG.debug("Caught exception while parsing out lldp optional and custom fields", e);
}
}
return nodeConnectorRef;
}
use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload 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.rpcbench.payload.rev150702.payload.Payload in project genius by opendaylight.
the class ArpUtilImpl method sendArpResponse.
@Override
public Future<RpcResult<Void>> sendArpResponse(SendArpResponseInput input) {
LOG.trace("sendArpResponse rpc invoked");
BigInteger dpnId;
byte[] payload;
byte[] srcMac;
try {
String interfaceName = input.getInterface();
GetPortFromInterfaceOutput portResult = getPortFromInterface(interfaceName);
checkNotNull(portResult);
dpnId = portResult.getDpid();
Long portid = portResult.getPortno();
NodeConnectorRef ref = MDSALUtil.getNodeConnRef(dpnId, portid.toString());
checkArgument(null != dpnId && !BigInteger.ZERO.equals(dpnId), ArpConstants.DPN_NOT_FOUND_ERROR, interfaceName);
checkNotNull(ref, ArpConstants.NODE_CONNECTOR_NOT_FOUND_ERROR, interfaceName);
LOG.trace("sendArpRequest received dpnId {} out interface {}", dpnId, interfaceName);
byte[] srcIpBytes = getIpAddressBytes(input.getSrcIpaddress());
byte[] dstIpBytes = getIpAddressBytes(input.getDstIpaddress());
if (input.getSrcMacaddress() == null) {
srcMac = portResult.getPhyAddress().getBytes("UTF-8");
} else {
String macAddr = input.getSrcMacaddress().getValue();
srcMac = HexEncode.bytesFromHexString(macAddr);
}
byte[] dstMac = NWUtil.parseMacAddress(input.getDstMacaddress().getValue());
checkNotNull(srcIpBytes, ArpConstants.FAILED_TO_GET_SRC_IP_FOR_INTERFACE, interfaceName);
payload = ArpPacketUtil.getPayload(ArpConstants.ARP_RESPONSE_OP, srcMac, srcIpBytes, dstMac, dstIpBytes);
List<Action> actions = getEgressAction(interfaceName);
sendPacketOutWithActions(dpnId, payload, ref, actions);
LOG.debug("Sent ARP response for IP {}, from source MAC {} to target MAC {} and target IP {} via dpnId {}", input.getSrcIpaddress().getIpv4Address().getValue(), HexEncode.bytesToHexStringFormat(srcMac), HexEncode.bytesToHexStringFormat(dstMac), input.getDstIpaddress().getIpv4Address().getValue(), dpnId);
} catch (UnknownHostException | PacketException | InterruptedException | UnsupportedEncodingException | ExecutionException e) {
LOG.error("failed to send arp response for {}: ", input.getSrcIpaddress(), e);
return RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, e.getMessage(), e).buildFuture();
}
RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.success();
return Futures.immediateFuture(rpcResultBuilder.build());
}
use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload in project genius by opendaylight.
the class ArpUtilImpl method sendArpRequest.
@Override
public Future<RpcResult<Void>> sendArpRequest(SendArpRequestInput arpReqInput) {
LOG.trace("rpc sendArpRequest invoked for ip {}", arpReqInput.getIpaddress());
BigInteger dpnId;
byte[] payload;
String interfaceName = null;
byte[] srcIpBytes;
byte[] dstIpBytes;
byte[] srcMac;
RpcResultBuilder<Void> failureBuilder = RpcResultBuilder.failed();
RpcResultBuilder<Void> successBuilder = RpcResultBuilder.success();
try {
dstIpBytes = getIpAddressBytes(arpReqInput.getIpaddress());
} catch (UnknownHostException e) {
LOG.error("Cannot get IP address", e);
failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.UNKNOWN_IP_ADDRESS_SUPPLIED);
return Futures.immediateFuture(failureBuilder.build());
}
int localErrorCount = 0;
for (InterfaceAddress interfaceAddress : arpReqInput.getInterfaceAddress()) {
try {
interfaceName = interfaceAddress.getInterface();
srcIpBytes = getIpAddressBytes(interfaceAddress.getIpAddress());
GetPortFromInterfaceOutput portResult = getPortFromInterface(interfaceName);
checkNotNull(portResult);
dpnId = portResult.getDpid();
Long portid = portResult.getPortno();
checkArgument(null != dpnId && !BigInteger.ZERO.equals(dpnId), ArpConstants.DPN_NOT_FOUND_ERROR, interfaceName);
NodeConnectorRef ref = MDSALUtil.getNodeConnRef(dpnId, portid.toString());
checkNotNull(ref, ArpConstants.NODE_CONNECTOR_NOT_FOUND_ERROR, interfaceName);
LOG.trace("sendArpRequest received dpnId {} out interface {}", dpnId, interfaceName);
if (interfaceAddress.getMacaddress() == null) {
srcMac = MDSALUtil.getMacAddressForNodeConnector(dataBroker, (InstanceIdentifier<NodeConnector>) ref.getValue());
} else {
String macAddr = interfaceAddress.getMacaddress().getValue();
srcMac = HexEncode.bytesFromHexString(macAddr);
}
checkNotNull(srcMac, ArpConstants.FAILED_TO_GET_SRC_MAC_FOR_INTERFACE, interfaceName, ref.getValue());
checkNotNull(srcIpBytes, ArpConstants.FAILED_TO_GET_SRC_IP_FOR_INTERFACE, interfaceName);
payload = ArpPacketUtil.getPayload(ArpConstants.ARP_REQUEST_OP, srcMac, srcIpBytes, ArpPacketUtil.ETHERNET_BROADCAST_DESTINATION, dstIpBytes);
List<Action> actions = getEgressAction(interfaceName);
sendPacketOutWithActions(dpnId, payload, ref, actions);
LOG.trace("sent arp request for {}", arpReqInput.getIpaddress());
} catch (UnknownHostException | PacketException | InterruptedException | ExecutionException | ReadFailedException e) {
LOG.trace("failed to send arp req for {} on interface {}", arpReqInput.getIpaddress(), interfaceName);
failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
successBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
localErrorCount++;
}
}
if (localErrorCount == arpReqInput.getInterfaceAddress().size()) {
// All the requests failed
return Futures.immediateFuture(failureBuilder.build());
}
return Futures.immediateFuture(successBuilder.build());
}
Aggregations