Search in sources :

Example 81 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions 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 82 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions 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 83 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project genius by opendaylight.

the class ArpUtilImpl method sendPacketOutWithActions.

private Future<RpcResult<Void>> sendPacketOutWithActions(BigInteger dpnId, byte[] payload, NodeConnectorRef ref, List<Action> actions) {
    NodeConnectorRef nodeConnectorRef = MDSALUtil.getNodeConnRef(dpnId, "0xfffffffd");
    TransmitPacketInput transmitPacketInput = new TransmitPacketInputBuilder().setPayload(payload).setNode(new NodeRef(InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:" + dpnId))).toInstance())).setIngress(nodeConnectorRef).setEgress(ref).setAction(actions).build();
    LOG.trace("PacketOut message framed for transmitting {}", transmitPacketInput);
    return packetProcessingService.transmitPacket(transmitPacketInput);
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Example 84 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project genius by opendaylight.

the class MDSALUtil method buildWriteActionsInstruction.

/**
 * Build write actions instruction with the given actions and key.
 *
 * @param actions the actions.
 * @param instructionKey the instruction key.
 * @return the instruction.
 */
public static Instruction buildWriteActionsInstruction(List<Action> actions, int instructionKey) {
    WriteActions writeActions = new WriteActionsBuilder().setAction(actions).build();
    WriteActionsCase writeActionsCase = new WriteActionsCaseBuilder().setWriteActions(writeActions).build();
    InstructionBuilder instructionBuilder = new InstructionBuilder();
    instructionBuilder.setInstruction(writeActionsCase);
    instructionBuilder.setKey(new InstructionKey(instructionKey));
    return instructionBuilder.build();
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder) WriteActions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) InstructionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey)

Example 85 with Actions

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions in project genius by opendaylight.

the class InstructionApplyActionsTest method verifyInstructionInfo.

private void verifyInstructionInfo(InstructionInfo instructionInfo) {
    Instruction instruction = instructionInfo.buildInstruction(2);
    assertEquals(2, instruction.getKey().getOrder().intValue());
    assertTrue(instruction.getInstruction() instanceof ApplyActionsCase);
    ApplyActionsCase applyActionsCase = (ApplyActionsCase) instruction.getInstruction();
    List<Action> actions = applyActionsCase.getApplyActions().getAction();
    assertEquals(1, actions.size());
    Action action = actions.get(0);
    assertTrue(action.getAction() instanceof GroupActionCase);
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) GroupActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)

Aggregations

ArrayList (java.util.ArrayList)112 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)67 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)45 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)42 Test (org.junit.Test)38 PushVlanActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder)33 GroupActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder)32 PopMplsActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder)32 PopPbbActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder)32 PopVlanActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder)32 PushMplsActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder)32 PushPbbActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder)32 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)29 ByteBuf (io.netty.buffer.ByteBuf)28 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder)26 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder)24 SetMplsTtlActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder)22 SetNwTtlActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder)22 SetQueueActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder)22 BigInteger (java.math.BigInteger)21