Search in sources :

Example 16 with Sent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent 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 17 with Sent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent in project bgpcep by opendaylight.

the class NeighborStateCliUtils method printMessagesState.

private static void printMessagesState(final State neighborState, final ShellTable table) {
    final BgpNeighborStateAugmentation state = neighborState.getAugmentation(BgpNeighborStateAugmentation.class);
    if (state == null) {
        return;
    }
    addHeader(table, "Messages state");
    final Messages messages = state.getMessages();
    table.addRow().addContent("Messages Received", "");
    final Received received = messages.getReceived();
    table.addRow().addContent("NOTIFICATION", received.getNOTIFICATION());
    table.addRow().addContent("UPDATE", received.getUPDATE());
    final Sent sent = messages.getSent();
    table.addRow().addContent("Messages Sent", "");
    table.addRow().addContent("NOTIFICATION", sent.getNOTIFICATION());
    table.addRow().addContent("UPDATE", sent.getUPDATE());
}
Also used : Messages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.Messages) Received(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received) BgpNeighborStateAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.BgpNeighborStateAugmentation) Sent(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent)

Example 18 with Sent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent in project bgpcep by opendaylight.

the class NeighborStateCliUtils method printAfiSafiState.

private static void printAfiSafiState(final AfiSafi afiSafi, final ShellTable table) {
    final NeighborAfiSafiStateAugmentation state = afiSafi.getState().getAugmentation(NeighborAfiSafiStateAugmentation.class);
    addHeader(table, "AFI state");
    table.addRow().addContent("Family", afiSafi.getAfiSafiName().getSimpleName());
    table.addRow().addContent("Active", state.isActive());
    final Prefixes prefixes = state.getPrefixes();
    if (prefixes == null) {
        return;
    }
    table.addRow().addContent("Prefixes", "");
    table.addRow().addContent("Installed", prefixes.getInstalled());
    table.addRow().addContent("Sent", prefixes.getSent());
    table.addRow().addContent("Received", prefixes.getReceived());
}
Also used : NeighborAfiSafiStateAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborAfiSafiStateAugmentation) Prefixes(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.operational.rev151009.bgp.neighbor.prefix.counters_state.Prefixes)

Example 19 with Sent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent in project bgpcep by opendaylight.

the class BGPSessionImpl method terminate.

/**
 * Closes BGP session from the parent with given reason. A message needs to be sent, but parent doesn't have to be
 * modified, because he initiated the closing. (To prevent concurrent modification exception).
 *
 * @param e BGPDocumentedException
 */
@VisibleForTesting
synchronized void terminate(final BGPDocumentedException e) {
    final BGPError error = e.getError();
    final byte[] data = e.getData();
    final NotifyBuilder builder = new NotifyBuilder().setErrorCode(error.getCode()).setErrorSubcode(error.getSubcode());
    if (data != null && data.length != 0) {
        builder.setData(data);
    }
    this.writeAndFlush(builder.build());
    notifyTerminationReasonAndCloseWithoutMessage(error.getCode(), error.getSubcode());
}
Also used : BGPError(org.opendaylight.protocol.bgp.parser.BGPError) NotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 20 with Sent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent in project bgpcep by opendaylight.

the class AbstractBGPSessionNegotiator method startNegotiation.

private synchronized void startNegotiation() {
    if (!(this.state == State.IDLE || this.state == State.OPEN_CONFIRM)) {
        return;
    }
    // Open can be sent first either from ODL (IDLE) or from peer (OPEN_CONFIRM)
    final IpAddress remoteIp = getRemoteIp();
    try {
        // Check if peer is configured in registry before retrieving preferences
        if (!this.registry.isPeerConfigured(remoteIp)) {
            final BGPDocumentedException cause = new BGPDocumentedException(String.format("BGP peer with ip: %s not configured, check configured peers in : %s", remoteIp, this.registry), BGPError.CONNECTION_REJECTED);
            negotiationFailed(cause);
            return;
        }
        final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
        int as = preferences.getMyAs().getValue().intValue();
        // Set as AS_TRANS if the value is bigger than 2B
        if (as > Values.UNSIGNED_SHORT_MAX_VALUE) {
            as = AS_TRANS;
        }
        sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(preferences.getHoldTime()).setBgpIdentifier(preferences.getBgpId()).setBgpParameters(preferences.getParams()).build());
        if (this.state != State.FINISHED) {
            this.state = State.OPEN_SENT;
            this.pending = this.channel.eventLoop().schedule(() -> {
                synchronized (AbstractBGPSessionNegotiator.this) {
                    AbstractBGPSessionNegotiator.this.pending = null;
                    if (AbstractBGPSessionNegotiator.this.state != State.FINISHED) {
                        AbstractBGPSessionNegotiator.this.sendMessage(buildErrorNotify(BGPError.HOLD_TIMER_EXPIRED));
                        negotiationFailed(new BGPDocumentedException("HoldTimer expired", BGPError.FSM_ERROR));
                        AbstractBGPSessionNegotiator.this.state = State.FINISHED;
                    }
                }
            }, INITIAL_HOLDTIMER, TimeUnit.MINUTES);
        }
    } catch (final Exception e) {
        LOG.warn("Unexpected negotiation failure", e);
        negotiationFailedCloseChannel(e);
    }
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) BGPSessionPreferences(org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException)

Aggregations

ArrayList (java.util.ArrayList)8 ExecutionException (java.util.concurrent.ExecutionException)8 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)7 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)4 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)4 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)4 UnknownHostException (java.net.UnknownHostException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 BigInteger (java.math.BigInteger)2 InetSocketAddress (java.net.InetSocketAddress)2 Date (java.util.Date)2 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)2 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)2 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)2 TunnelTypeVxlan (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan)2 GetPortFromInterfaceOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput)2 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)2