Search in sources :

Example 1 with GetPortFromInterfaceOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput in project genius by opendaylight.

the class InterfaceManagerConfigurationTest method checkVlanRpcs.

private void checkVlanRpcs() throws Exception {
    // 1. Test dpn-id fetching from interface
    GetDpidFromInterfaceInput dpidFromInterfaceInput = new GetDpidFromInterfaceInputBuilder().setIntfName(INTERFACE_NAME).build();
    Future<RpcResult<GetDpidFromInterfaceOutput>> dpidFromInterfaceOutput = odlInterfaceRpcService.getDpidFromInterface(dpidFromInterfaceInput);
    Assert.assertEquals(DpnFromInterfaceOutput.newDpnFromInterfaceOutput(), dpidFromInterfaceOutput.get().getResult());
    // 3. Test egress actions fetching for interface
    GetEgressActionsForInterfaceInput egressActionsForInterfaceInput = new GetEgressActionsForInterfaceInputBuilder().setIntfName(INTERFACE_NAME).build();
    Future<RpcResult<GetEgressActionsForInterfaceOutput>> egressActionsForInterfaceOutput = odlInterfaceRpcService.getEgressActionsForInterface(egressActionsForInterfaceInput);
    assertEqualBeans(EgressActionsForInterfaceOutput.newEgressActionsForInterfaceOutput(), egressActionsForInterfaceOutput.get().getResult());
    // 4. Test egress instructions fetching for interface
    GetEgressInstructionsForInterfaceInput egressInstructionsForInterfaceInput = new GetEgressInstructionsForInterfaceInputBuilder().setIntfName(INTERFACE_NAME).build();
    Future<RpcResult<GetEgressInstructionsForInterfaceOutput>> egressInstructionsForInterfaceOutput = odlInterfaceRpcService.getEgressInstructionsForInterface(egressInstructionsForInterfaceInput);
    assertEqualBeans(EgressInstructionsForInterfaceOutput.newEgressInstructionsForInterfaceOutput(), egressInstructionsForInterfaceOutput.get().getResult());
    // 5. Test interface fetching from if-index
    /* FIXME can be tested only once ResourceBatchingManager becomes testable
        GetInterfaceFromIfIndexInput interfaceFromIfIndexInput = new GetInterfaceFromIfIndexInputBuilder()
                .setIfIndex(1).build();
        Future<RpcResult<GetInterfaceFromIfIndexOutput>> interfaceFromIfIndexOutput = odlInterfaceRpcService
            .getInterfaceFromIfIndex(interfaceFromIfIndexInput);
        assertEqualBeans(InterfaceFromIfIndexOutput.newInterfaceFromIfIndexOutput(),
                interfaceFromIfIndexOutput.get().getResult());*/
    // 6. Test interface type fetching from interface-name
    GetInterfaceTypeInput interfaceTypeInput = new GetInterfaceTypeInputBuilder().setIntfName(INTERFACE_NAME).build();
    Future<RpcResult<GetInterfaceTypeOutput>> interfaceTypeOutput = odlInterfaceRpcService.getInterfaceType(interfaceTypeInput);
    assertEqualBeans(InterfaceTypeOutput.newInterfaceTypeOutput(), interfaceTypeOutput.get().getResult());
    // 7. Test get nodeconnector-id from interface-name
    GetNodeconnectorIdFromInterfaceInput nodeconnectorIdFromInterfaceInput = new GetNodeconnectorIdFromInterfaceInputBuilder().setIntfName(INTERFACE_NAME).build();
    Future<RpcResult<GetNodeconnectorIdFromInterfaceOutput>> nodeconnectorIdFromInterfaceOutput = odlInterfaceRpcService.getNodeconnectorIdFromInterface(nodeconnectorIdFromInterfaceInput);
    assertEqualBeans(NodeconnectorIdFromInterfaceOutput.newNodeconnectorIdFromInterfaceOutput(), nodeconnectorIdFromInterfaceOutput.get().getResult());
    // 8. Test get port details from interface-name
    GetPortFromInterfaceInput portFromInterfaceInput = new GetPortFromInterfaceInputBuilder().setIntfName(INTERFACE_NAME).build();
    Future<RpcResult<GetPortFromInterfaceOutput>> portFromInterfaceOutput = odlInterfaceRpcService.getPortFromInterface(portFromInterfaceInput);
    assertEqualBeans(PortFromInterfaceOutput.newPortFromInterfaceOutput(), portFromInterfaceOutput.get().getResult());
}
Also used : GetDpidFromInterfaceInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInput) GetDpidFromInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder) GetEgressActionsForInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceInputBuilder) GetEgressInstructionsForInterfaceInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressInstructionsForInterfaceInput) GetNodeconnectorIdFromInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetNodeconnectorIdFromInterfaceInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetPortFromInterfaceInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInput) GetPortFromInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInputBuilder) GetInterfaceTypeInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetInterfaceTypeInput) GetInterfaceTypeInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetInterfaceTypeInputBuilder) GetEgressActionsForInterfaceInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceInput) GetNodeconnectorIdFromInterfaceInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetNodeconnectorIdFromInterfaceInput) GetEgressInstructionsForInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressInstructionsForInterfaceInputBuilder)

Example 2 with GetPortFromInterfaceOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput in project genius by opendaylight.

the class InterfacemgrProvider method getPortForInterface.

@Override
public Long getPortForInterface(String ifName) {
    GetPortFromInterfaceInput input = new GetPortFromInterfaceInputBuilder().setIntfName(ifName).build();
    Future<RpcResult<GetPortFromInterfaceOutput>> output = interfaceManagerRpcService.getPortFromInterface(input);
    try {
        RpcResult<GetPortFromInterfaceOutput> port = output.get();
        if (port.isSuccessful()) {
            return port.getResult().getPortno();
        }
    } catch (NullPointerException | InterruptedException | ExecutionException e) {
        LOG.warn("Exception when getting port for interface", e);
    }
    return null;
}
Also used : GetPortFromInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetPortFromInterfaceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput) ExecutionException(java.util.concurrent.ExecutionException) GetPortFromInterfaceInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInput)

Example 3 with GetPortFromInterfaceOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput 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 4 with GetPortFromInterfaceOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput 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());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) InterfaceAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) BigInteger(java.math.BigInteger) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) GetPortFromInterfaceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with GetPortFromInterfaceOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput in project genius by opendaylight.

the class ArpUtilImpl method getPortFromInterface.

private GetPortFromInterfaceOutput getPortFromInterface(String interfaceName) throws InterruptedException, ExecutionException {
    GetPortFromInterfaceInputBuilder getPortFromInterfaceInputBuilder = new GetPortFromInterfaceInputBuilder();
    getPortFromInterfaceInputBuilder.setIntfName(interfaceName);
    Future<RpcResult<GetPortFromInterfaceOutput>> portFromInterface = odlInterfaceRpcService.getPortFromInterface(getPortFromInterfaceInputBuilder.build());
    GetPortFromInterfaceOutput result = portFromInterface.get().getResult();
    LOG.trace("getPortFromInterface rpc result is {} ", result);
    if (result != null) {
        LOG.trace("getPortFromInterface rpc result is {} {} ", result.getDpid(), result.getPortno());
    }
    return result;
}
Also used : GetPortFromInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetPortFromInterfaceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput)

Aggregations

GetPortFromInterfaceOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput)9 ExecutionException (java.util.concurrent.ExecutionException)6 GetPortFromInterfaceInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInputBuilder)6 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 BigInteger (java.math.BigInteger)4 GetPortFromInterfaceInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInput)4 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)3 UnknownHostException (java.net.UnknownHostException)2 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)2 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)2 GetPortFromInterfaceOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutputBuilder)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Collections (java.util.Collections)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)1 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)1 InterfaceAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress)1 GetDpidFromInterfaceInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInput)1 GetDpidFromInterfaceInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder)1 GetEgressActionsForInterfaceInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceInput)1