Search in sources :

Example 1 with SendArpResponseInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpResponseInput 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());
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) BigInteger(java.math.BigInteger) GetPortFromInterfaceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with SendArpResponseInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpResponseInput in project genius by opendaylight.

the class ArpUtilTest method testSendArpResponse.

@Test
public void testSendArpResponse() throws Exception {
    SendArpResponseInput builder = new SendArpResponseInputBuilder().setInterface(INTERFACE_NAME).setSrcIpaddress(new IpAddress(Ipv4Address.getDefaultInstance("192.168.0.1"))).setDstIpaddress(new IpAddress(Ipv4Address.getDefaultInstance("192.168.0.2"))).setSrcMacaddress(new PhysAddress("1F:1F:1F:1F:1F:1F")).setDstMacaddress(new PhysAddress("00:01:02:03:04:05")).build();
    Assert.assertEquals(true, odlArputilService.sendArpResponse(builder).get().isSuccessful());
}
Also used : SendArpResponseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpResponseInputBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) SendArpResponseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpResponseInput) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) Test(org.junit.Test)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigInteger (java.math.BigInteger)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)1 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)1 SendArpResponseInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpResponseInput)1 SendArpResponseInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpResponseInputBuilder)1 GetPortFromInterfaceOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput)1 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)1