Search in sources :

Example 1 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class PeerGroupStateCliUtils method displayState.

private static void displayState(final PeerGroup group, final ShellTable table) {
    addHeader(table, "Peer Group state");
    table.addRow().addContent("Peer Group Name", group.getPeerGroupName());
    final State state = group.getState();
    if (state == null) {
        return;
    }
    final PeerGroupStateAugmentation aug = state.getAugmentation(PeerGroupStateAugmentation.class);
    table.addRow().addContent("Total Prefixes", aug.getTotalPrefixes());
}
Also used : State(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.State) PeerGroupStateAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.PeerGroupStateAugmentation)

Example 2 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class PeerGroupStateCliUtilsTest method testPeerGroupStateCli.

@Test
public void testPeerGroupStateCli() throws IOException {
    final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
    final PeerGroupStateAugmentation groupState = new PeerGroupStateAugmentationBuilder().setTotalPrefixes(1L).setTotalPaths(2L).build();
    peerGroup.setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.StateBuilder().addAugmentation(PeerGroupStateAugmentation.class, groupState).build());
    PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
    final String expected = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("peer-group.txt"), UTF8);
    assertEquals(expected, this.output.toString());
}
Also used : PeerGroupStateAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.PeerGroupStateAugmentationBuilder) PeerGroupBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder) PeerGroupStateAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.PeerGroupStateAugmentation) Test(org.junit.Test)

Example 3 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class StateProviderImplTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    doReturn(Optional.of(IPV4UNICAST.class)).when(this.tableTypeRegistry).getAfiSafiType(eq(TABLES_KEY));
    doReturn(this.bgpRibStates).when(this.stateCollector).getRibStats();
    doReturn(this.bgpPeerStates).when(this.stateCollector).getPeerStats();
    final KeyedInstanceIdentifier<Rib, RibKey> iid = InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(new RibId(this.ribId)));
    doReturn(iid).when(this.bgpRibState).getInstanceIdentifier();
    doReturn(this.as).when(this.bgpRibState).getAs();
    doReturn(this.bgpId).when(this.bgpRibState).getRouteId();
    doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpRibState).getTotalPathsCount();
    doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpRibState).getTotalPrefixesCount();
    doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpRibState).getPathCount(eq(TABLES_KEY));
    doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpRibState).getPrefixesCount(eq(TABLES_KEY));
    doAnswer(invocation -> Collections.singletonMap(TABLES_KEY, this.totalPrefixesCounter.longValue())).when(this.bgpRibState).getTablesPrefixesCount();
    doAnswer(invocation -> Collections.singletonMap(TABLES_KEY, this.totalPathsCounter.longValue())).when(this.bgpRibState).getPathsCount();
    // Mock Peer
    doReturn("test-group").when(this.bgpPeerState).getGroupId();
    doReturn(iid).when(this.bgpPeerState).getInstanceIdentifier();
    doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpPeerState).getTotalPrefixes();
    doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpPeerState).getTotalPathsCount();
    doReturn(this.neighborAddress).when(this.bgpPeerState).getNeighborAddress();
    doReturn(this.bgpSessionState).when(this.bgpPeerState).getBGPSessionState();
    doReturn(this.bgpPeerMessagesState).when(this.bgpPeerState).getBGPPeerMessagesState();
    doReturn(1L).when(this.bgpPeerMessagesState).getNotificationMessagesReceivedCount();
    doReturn(1L).when(this.bgpPeerMessagesState).getNotificationMessagesSentCount();
    doReturn(1L).when(this.bgpPeerMessagesState).getUpdateMessagesReceivedCount();
    doReturn(1L).when(this.bgpPeerMessagesState).getUpdateMessagesSentCount();
    doReturn(State.UP).when(this.bgpSessionState).getSessionState();
    doReturn(true).when(this.bgpSessionState).isAddPathCapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isAsn32CapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isGracefulRestartCapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isMultiProtocolCapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isRouterRefreshCapabilitySupported();
    doReturn(this.timersState).when(this.bgpPeerState).getBGPTimersState();
    doReturn(10L).when(this.timersState).getNegotiatedHoldTime();
    doReturn(1L).when(this.timersState).getUpTime();
    doReturn(this.bgpTransportState).when(this.bgpPeerState).getBGPTransportState();
    doReturn(this.localPort).when(this.bgpTransportState).getLocalPort();
    doReturn(this.neighborAddress).when(this.bgpTransportState).getRemoteAddress();
    doReturn(this.remotePort).when(this.bgpTransportState).getRemotePort();
    doReturn(this.bgpErrorHandlingState).when(this.bgpPeerState).getBGPErrorHandlingState();
    doReturn(1L).when(this.bgpErrorHandlingState).getErroneousUpdateReceivedCount();
    doReturn(this.bgpGracelfulRestartState).when(this.bgpPeerState).getBGPGracelfulRestart();
    doReturn(true).when(this.bgpGracelfulRestartState).isGracefulRestartAdvertized(any());
    doReturn(true).when(this.bgpGracelfulRestartState).isGracefulRestartReceived(any());
    doReturn(true).when(this.bgpGracelfulRestartState).isLocalRestarting();
    doReturn(true).when(this.bgpGracelfulRestartState).isPeerRestarting();
    doReturn(this.restartTime).when(this.bgpGracelfulRestartState).getPeerRestartTime();
    doReturn(this.bgpAfiSafiState).when(this.bgpPeerState).getBGPAfiSafiState();
    doReturn(Collections.singleton(TABLES_KEY)).when(this.bgpAfiSafiState).getAfiSafisAdvertized();
    doReturn(Collections.singleton(TABLES_KEY)).when(this.bgpAfiSafiState).getAfiSafisReceived();
    doReturn(1L).when(this.bgpAfiSafiState).getPrefixesInstalledCount(any());
    doReturn(2L).when(this.bgpAfiSafiState).getPrefixesReceivedCount(any());
    doReturn(1L).when(this.bgpAfiSafiState).getPrefixesSentCount(any());
    doReturn(true).when(this.bgpAfiSafiState).isAfiSafiSupported(any());
    doReturn(true).when(this.bgpAfiSafiState).isGracefulRestartAdvertized(any());
    doReturn(true).when(this.bgpAfiSafiState).isGracefulRestartReceived(any());
}
Also used : RibId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.RibId) RibKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.RibKey) Rib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.Rib) BgpRib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.BgpRib) IPV4UNICAST(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST) BgpRib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.BgpRib) Before(org.junit.Before)

Example 4 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class AbstractBGPSessionNegotiator method handleMessage.

protected synchronized void handleMessage(final Notification msg) {
    LOG.debug("Channel {} handling message in state {}, msg: {}", this.channel, this.state, msg);
    switch(this.state) {
        case FINISHED:
            sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
            return;
        case IDLE:
            // to avoid race condition when Open message was sent by the peer before startNegotiation could be executed
            if (msg instanceof Open) {
                startNegotiation();
                handleOpen((Open) msg);
                return;
            }
            sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
            break;
        case OPEN_CONFIRM:
            if (msg instanceof Keepalive) {
                negotiationSuccessful(this.session);
                LOG.info("BGP Session with peer {} established successfully.", this.channel);
            } else if (msg instanceof Notify) {
                final Notify ntf = (Notify) msg;
                negotiationFailed(new BGPDocumentedException("Peer refusal", BGPError.forValue(ntf.getErrorCode(), ntf.getErrorSubcode())));
            }
            this.state = State.FINISHED;
            return;
        case OPEN_SENT:
            if (msg instanceof Open) {
                handleOpen((Open) msg);
                return;
            }
            break;
        default:
            break;
    }
    // Catch-all for unexpected message
    LOG.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
    sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
    negotiationFailed(new BGPDocumentedException("Unexpected message channel: " + this.channel + ", state: " + this.state + ", message: " + msg, BGPError.FSM_ERROR));
    this.state = State.FINISHED;
}
Also used : Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)

Example 5 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class AbstractBGPSessionNegotiator method handleOpen.

private synchronized void handleOpen(final Open openObj) {
    final IpAddress remoteIp = getRemoteIp();
    final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
    try {
        final BGPSessionListener peer = this.registry.getPeer(remoteIp, getSourceId(openObj, preferences), getDestinationId(openObj, preferences), openObj);
        sendMessage(new KeepaliveBuilder().build());
        this.state = State.OPEN_CONFIRM;
        this.session = new BGPSessionImpl(peer, this.channel, openObj, preferences, this.registry);
        this.session.setChannelExtMsgCoder(openObj);
        LOG.debug("Channel {} moved to OPEN_CONFIRM state with remote proposal {}", this.channel, openObj);
    } catch (final BGPDocumentedException e) {
        LOG.warn("Channel {} negotiation failed", this.channel, e);
        negotiationFailed(e);
    }
}
Also used : BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener) 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) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.KeepaliveBuilder)

Aggregations

Test (org.junit.Test)23 ByteBuf (io.netty.buffer.ByteBuf)12 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)10 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)9 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)6 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)5 ArrayList (java.util.ArrayList)4 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)4 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)4 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)4 PortStatusMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)4 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)4 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)4 Preconditions (com.google.common.base.Preconditions)3 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)3 BGPSessionListener (org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener)3 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3