use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId in project bgpcep by opendaylight.
the class TestUtil method createPeerDownNotification.
public static PeerDownNotification createPeerDownNotification(final Ipv4Address bgpId) {
final NotificationBuilder notifBuilder = new NotificationBuilder().setNotification(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder().setErrorCode((short) 1).setErrorSubcode((short) 1).build());
final PeerDownNotificationBuilder peerDownNotifBuilder = new PeerDownNotificationBuilder().setData(notifBuilder.build()).setLocalSystemClosed(true).setPeerHeader(TestUtil.createPeerHeader(bgpId));
return peerDownNotifBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId in project bgpcep by opendaylight.
the class RibImpl method createRib.
private synchronized RIBImpl createRib(final Global global, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
afiSafi = getAfiSafiWithDefault(global.getAfiSafis(), true).values();
final Config globalConfig = global.getConfig();
asNumber = globalConfig.getAs();
routerId = IetfInetUtil.INSTANCE.ipv4AddressNoZoneFor(globalConfig.getRouterId());
clusterId = getGlobalClusterIdentifier(globalConfig);
final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil.toPathSelectionMode(afiSafi, tableTypeRegistry).entrySet().stream().collect(Collectors.toMap(entry -> new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
final BGPRibRoutingPolicy ribPolicy = policyProvider.buildBGPRibPolicy(asNumber.getValue().toJava(), routerId, clusterId, RoutingPolicyUtil.getApplyPolicy(global.getApplyPolicy()));
return new RIBImpl(tableTypeRegistry, ribId, asNumber, new BgpId(routerId), extensionProvider, dispatcher, codecsRegistry, domBroker, ribPolicy, toTableTypes(afiSafi, tableTypeRegistry), pathSelectionModes);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId in project bgpcep by opendaylight.
the class FSMTest method setUp.
@Before
public void setUp() throws UnknownHostException {
MockitoAnnotations.initMocks(this);
final List<BgpParameters> tlvs = new ArrayList<>();
final List<OptionalCapabilities> capas = new ArrayList<>();
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(this.linkstatett.getAfi()).setSafi(this.linkstatett.getSafi()).build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(30))).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().build()).build()).build()).build());
tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
final BGPSessionPreferences prefs = new BGPSessionPreferences(new AsNumber(Uint32.valueOf(30)), (short) 3, new BgpId("1.1.1.1"), new AsNumber(Uint32.valueOf(30)), tlvs);
final ChannelFuture f = mock(ChannelFuture.class);
doReturn(null).when(f).addListener(any(GenericFutureListener.class));
final InetAddress peerAddress = InetAddress.getByName("1.1.1.2");
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
FSMTest.this.receivedMsgs.add((Notification) args[0]);
return f;
}).when(this.speakerListener).writeAndFlush(any(Notification.class));
doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn("TestingChannel").when(this.speakerListener).toString();
doReturn(new InetSocketAddress(peerAddress, 179)).when(this.speakerListener).remoteAddress();
doReturn(new InetSocketAddress(peerAddress, 179)).when(this.speakerListener).localAddress();
doReturn(this.pipeline).when(this.speakerListener).pipeline();
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(null).when(this.pipeline).replace(ArgumentMatchers.<Class<ChannelHandler>>any(), any(String.class), any(ChannelHandler.class));
doReturn(this.pipeline).when(this.pipeline).addLast(any(ChannelHandler.class));
doReturn(mock(ChannelFuture.class)).when(this.speakerListener).close();
final BGPPeerRegistry peerRegistry = new StrictBGPPeerRegistry();
peerRegistry.addPeer(new IpAddressNoZone(new Ipv4AddressNoZone(peerAddress.getHostAddress())), new SimpleSessionListener(), prefs);
this.clientSession = new BGPClientSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE), this.speakerListener, peerRegistry);
this.classicOpen = new OpenBuilder().setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(3)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(tlvs).setBgpIdentifier(new Ipv4AddressNoZone("1.1.1.2")).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId in project bgpcep by opendaylight.
the class SynchronizationAndExceptionTest method testHandleMessageAfterException.
@Test
public void testHandleMessageAfterException() {
final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy());
final RIBImpl ribImpl = new RIBImpl(this.tableRegistry, new RibId(RIB_ID), AS_NUMBER, new BgpId(RIB_ID), this.ribExtension, this.serverDispatcher, this.codecsRegistry, this.domBroker, this.policies, ImmutableList.of(this.ipv4tt), pathTables);
ribImpl.instantiateServiceInstance();
final BGPPeer bgpPeer = AbstractAddPathTest.configurePeer(this.tableRegistry, neighbor.getIpv4AddressNoZone(), ribImpl, null, PeerRole.Ibgp, this.serverRegistry, AFI_SAFIS_ADVERTIZED, Collections.emptySet());
bgpPeer.instantiateServiceInstance();
final BGPSessionImpl bgpSession = new BGPSessionImpl(bgpPeer, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer().toJava(), null);
bgpSession.setChannelExtMsgCoder(this.classicOpen);
bgpPeer.onSessionUp(bgpSession);
final Nlri n1 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
final Nlri n2 = new NlriBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
final Nlri n3 = new NlriBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
final List<Nlri> nlris = Lists.newArrayList(n1, n2, n3);
final UpdateBuilder wrongMessage = new UpdateBuilder();
wrongMessage.setNlri(nlris);
final Origin origin = new OriginBuilder().setValue(BgpOrigin.Igp).build();
final AsPath asPath = new AsPathBuilder().setSegments(Collections.emptyList()).build();
final CNextHop nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("127.0.0.1")).build()).build();
final AttributesBuilder ab = new AttributesBuilder();
wrongMessage.setAttributes(ab.setOrigin(origin).setAsPath(asPath).setCNextHop(nextHop).build());
final UpdateBuilder correct = new UpdateBuilder(wrongMessage.build());
correct.setAttributes(ab.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build()).build());
bgpSession.handleMessage(correct.build());
verify(this.tx, times(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
bgpSession.handleMessage(wrongMessage.build());
verify(this.tx, times(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
bgpSession.handleMessage(new UpdateBuilder().build());
verify(this.tx, times(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
verify(this.tx).delete(eq(LogicalDatastoreType.OPERATIONAL), eq(PEER_PATH));
verify(this.tx, times(0)).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(TABLE_PATH), eq(ImmutableNodes.leafNode(UPTODATE_NID, Boolean.TRUE)));
}
Aggregations