Search in sources :

Example 56 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp 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)

Example 57 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class PeerDownHandler method parseBgpNotificationMessage.

private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.Notification parseBgpNotificationMessage(final ByteBuf bytes) throws BmpDeserializationException {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder notificationCBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder notificationBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder();
    try {
        final Notification not = this.msgRegistry.parseMessage(bytes, null);
        requireNonNull(not, "Notify message may not be null.");
        Preconditions.checkArgument(not instanceof NotifyMessage, "An instance of NotifyMessage is required");
        notificationBuilder.fieldsFrom((NotifyMessage) not);
        notificationCBuilder.setNotification(notificationBuilder.build());
    } catch (final BGPDocumentedException | BGPParsingException e) {
        throw new BmpDeserializationException("Error while parsing BGP Notification message.", e);
    }
    return notificationCBuilder.build();
}
Also used : Preconditions(com.google.common.base.Preconditions) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) PeerDownNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification) Notification(org.opendaylight.yangtools.yang.binding.Notification) PeerDownNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotificationBuilder) NotifyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyMessage) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Example 58 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParserTest method testPerPeerHeader.

@Test
public void testPerPeerHeader() {
    final byte[] msgBytes = { (byte) 0x00, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, // IPV4 192.168.1.1
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01, // AS 168
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8, // Peer BGP ID 1.1.1.1
    (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, // Timestamp
    (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 };
    final PeerHeader perHeader = AbstractBmpPerPeerMessageParser.parsePerPeerHeader(Unpooled.wrappedBuffer(msgBytes));
    final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
    phBuilder.setType(PeerType.forValue(0));
    phBuilder.setAdjRibInType(AdjRibInType.forValue(1));
    phBuilder.setIpv4(true);
    phBuilder.setAddress(new IpAddress(new Ipv4Address("192.168.1.1")));
    phBuilder.setAs(new AsNumber(168L));
    phBuilder.setBgpId(new Ipv4Address("1.1.1.1"));
    phBuilder.setTimestampSec(new Timestamp(16909060L));
    phBuilder.setTimestampMicro(new Timestamp(16909060L));
    assertEquals(perHeader, phBuilder.build());
    final ByteBuf aggregator = Unpooled.buffer();
    this.parser.serializePerPeerHeader(perHeader, aggregator);
    assertArrayEquals(msgBytes, ByteArray.getAllBytes(aggregator));
}
Also used : PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) ByteBuf(io.netty.buffer.ByteBuf) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 59 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class BGPNotificationMessageParser method serializeMessage.

/**
 * Serializes BGP Notification message.
 *
 * @param msg to be serialized
 * @param bytes ByteBuf where the message will be serialized
 */
@Override
public void serializeMessage(final Notification msg, final ByteBuf bytes) {
    Preconditions.checkArgument(msg instanceof Notify, "Message needs to be of type Notify");
    final Notify ntf = (Notify) msg;
    final ByteBuf msgBody = Unpooled.buffer();
    msgBody.writeByte(ntf.getErrorCode());
    msgBody.writeByte(ntf.getErrorSubcode());
    final byte[] data = ntf.getData();
    if (data != null) {
        msgBody.writeBytes(data);
    }
    LOG.trace("Notification message serialized to: {}", ByteBufUtil.hexDump(msgBody));
    MessageUtil.formatMessage(TYPE, msgBody, bytes);
}
Also used : Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) ByteBuf(io.netty.buffer.ByteBuf)

Example 60 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class BGPOpenMessageParser method parseMessageBody.

/**
 * Parses given byte array to BGP Open message
 *
 * @param body byte array representing BGP Open message, without header
 * @param messageLength the length of the message
 * @return {@link Open} BGP Open Message
 * @throws BGPDocumentedException if the parsing was unsuccessful
 */
@Override
public Open parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
    Preconditions.checkArgument(body != null, "Buffer cannot be null.");
    if (body.readableBytes() < MIN_MSG_LENGTH) {
        throw BGPDocumentedException.badMessageLength("Open message too small.", messageLength);
    }
    final int version = body.readUnsignedByte();
    if (version != BGP_VERSION) {
        throw new BGPDocumentedException("BGP Protocol version " + version + " not supported.", BGPError.VERSION_NOT_SUPPORTED);
    }
    final AsNumber as = new AsNumber((long) body.readUnsignedShort());
    final int holdTime = body.readUnsignedShort();
    if (holdTime == 1 || holdTime == 2) {
        throw new BGPDocumentedException("Hold time value not acceptable.", BGPError.HOLD_TIME_NOT_ACC);
    }
    Ipv4Address bgpId = null;
    try {
        bgpId = Ipv4Util.addressForByteBuf(body);
    } catch (final IllegalArgumentException e) {
        throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID, e);
    }
    final int optLength = body.readUnsignedByte();
    final List<BgpParameters> optParams = new ArrayList<>();
    if (optLength > 0) {
        fillParams(body.slice(), optParams);
    }
    LOG.debug("BGP Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as, holdTime, bgpId, optParams);
    return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer(holdTime).setBgpIdentifier(bgpId).setBgpParameters(optParams).build();
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) ArrayList(java.util.ArrayList) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Aggregations

BigInteger (java.math.BigInteger)18 Test (org.junit.Test)17 ByteBuf (io.netty.buffer.ByteBuf)16 ArrayList (java.util.ArrayList)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)16 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)11 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)10 ExecutionException (java.util.concurrent.ExecutionException)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)9 Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)7 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)7 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)7 List (java.util.List)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)5 Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)5 Collections (java.util.Collections)4