2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
13 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
15 import com.google.common.collect.ImmutableList;
16 import com.google.common.collect.Lists;
17 import io.netty.channel.epoll.Epoll;
18 import io.netty.channel.nio.NioEventLoopGroup;
19 import io.netty.util.concurrent.Future;
20 import java.net.InetSocketAddress;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
25 import java.util.Optional;
27 import java.util.concurrent.TimeUnit;
28 import org.junit.After;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
34 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
35 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
36 import org.opendaylight.protocol.bgp.inet.RIBActivator;
37 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
38 import org.opendaylight.protocol.bgp.parser.BGPError;
39 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
40 import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
41 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
42 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
43 import org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer;
44 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
45 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
46 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
47 import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
48 import org.opendaylight.protocol.util.InetSocketAddressUtil;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.Ipv4Routes;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AsPathBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterIdBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPrefBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.as.path.SegmentsBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.update.message.WithdrawnRoutesBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpId;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpOrigin;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
92 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
93 import org.opendaylight.yangtools.yang.binding.Notification;
94 import org.opendaylight.yangtools.yang.common.Uint16;
95 import org.opendaylight.yangtools.yang.common.Uint32;
97 public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest {
98 private static final int RETRY_TIMER = 10;
99 static final String RIB_ID = "127.0.0.1";
100 static final BgpId BGP_ID = new BgpId(RIB_ID);
101 static final Ipv4AddressNoZone PEER1 = new Ipv4AddressNoZone("127.0.0.2");
102 static final Ipv4AddressNoZone PEER2 = new Ipv4AddressNoZone("127.0.0.3");
103 static final Ipv4AddressNoZone PEER3 = new Ipv4AddressNoZone("127.0.0.4");
104 static final Ipv4AddressNoZone PEER4 = new Ipv4AddressNoZone("127.0.0.5");
105 static final Ipv4AddressNoZone PEER5 = new Ipv4AddressNoZone("127.0.0.6");
106 static final Ipv4AddressNoZone PEER6 = new Ipv4AddressNoZone("127.0.0.7");
107 static final AsNumber AS_NUMBER = new AsNumber(Uint32.valueOf(AS));
108 static final Uint16 PORT = Uint16.valueOf(InetSocketAddressUtil.getRandomPort());
109 static final Ipv4Prefix PREFIX1 = new Ipv4Prefix("1.1.1.1/32");
110 private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier(RIB_ID);
111 static final int HOLDTIMER = 2180;
112 private static final Ipv4AddressNoZone NH1 = new Ipv4AddressNoZone("2.2.2.2");
113 static final Update UPD_100 = createSimpleUpdate(PREFIX1, new PathId(Uint32.ONE), CLUSTER_ID, 100);
114 static final Update UPD_50 = createSimpleUpdate(PREFIX1, new PathId(Uint32.TWO), CLUSTER_ID, 50);
115 static final Update UPD_200 = createSimpleUpdate(PREFIX1, new PathId(Uint32.valueOf(3)), CLUSTER_ID, 200);
116 static final Update UPD_20 = createSimpleUpdate(PREFIX1, new PathId(Uint32.ONE), CLUSTER_ID, 20);
117 static final Update UPD_NA_100 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 100);
118 static final Update UPD_NA_100_EBGP = createSimpleUpdateEbgp(PREFIX1);
119 static final Update UPD_NA_200 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 200);
120 static final Update UPD_NA_200_EBGP = createSimpleUpdateEbgp(PREFIX1);
121 static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
122 static final List<BgpTableType> TABLES_TYPE = ImmutableList.of(new BgpTableTypeImpl(TABLES_KEY.getAfi(),
123 TABLES_KEY.getSafi()));
124 static final Set<TablesKey> AFI_SAFIS_ADVERTIZED = Collections.singleton(TABLES_KEY);
125 private BGPExtensionProviderContext context;
126 static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
127 static final int GRACEFUL_RESTART_TIME = 5;
129 protected ClusterSingletonServiceProvider clusterSingletonServiceProvider;
130 BGPDispatcherImpl serverDispatcher;
131 RIBExtensionProviderContext ribExtension;
132 private RIBActivator ribActivator;
133 private BGPActivator bgpActivator;
134 private NioEventLoopGroup worker;
135 private NioEventLoopGroup boss;
136 private org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator;
137 protected StrictBGPPeerRegistry serverRegistry;
138 protected CodecsRegistryImpl codecsRegistry;
140 private List<BGPDispatcherImpl> clientDispatchers;
144 public void setUp() throws Exception {
146 this.ribActivator = new RIBActivator();
147 this.ribExtension = new SimpleRIBExtensionProviderContext();
149 this.ribActivator.startRIBExtensionProvider(this.ribExtension, this.mappingService);
151 this.bgpActivator = new BGPActivator();
152 this.inetActivator = new org.opendaylight.protocol.bgp.inet.BGPActivator();
153 this.context = new SimpleBGPExtensionProviderContext();
154 this.bgpActivator.start(this.context);
155 this.inetActivator.start(this.context);
156 if (!Epoll.isAvailable()) {
157 this.worker = new NioEventLoopGroup();
158 this.boss = new NioEventLoopGroup();
160 this.serverRegistry = new StrictBGPPeerRegistry();
161 this.serverDispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss, this.worker,
162 this.serverRegistry);
163 doReturn(Mockito.mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
164 .registerClusterSingletonService(any(ClusterSingletonService.class));
166 this.codecsRegistry = CodecsRegistryImpl.create(this.mappingService.getCodecFactory(),
167 this.ribExtension.getClassLoadingStrategy());
168 this.clientDispatchers = new ArrayList<>();
173 public void tearDown() throws Exception {
174 this.serverDispatcher.close();
175 if (!Epoll.isAvailable()) {
176 this.worker.shutdownGracefully(0, 0, TimeUnit.SECONDS);
177 this.boss.shutdownGracefully(0, 0, TimeUnit.SECONDS);
179 this.mappingService.close();
180 this.ribActivator.close();
181 this.inetActivator.close();
182 this.bgpActivator.close();
183 this.clientDispatchers.forEach(BGPDispatcherImpl::close);
184 this.clientDispatchers = null;
188 void sendRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference,
189 final int expectedRoutesOnDS) throws Exception {
190 waitFutureSuccess(session.writeAndFlush(createSimpleUpdate(prefix, null, null, localPreference)));
191 checkLocRib(expectedRoutesOnDS);
194 void sendWithdrawalRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix,
195 final long localPreference, final int expectedRoutesOnDS) throws Exception {
196 waitFutureSuccess(session.writeAndFlush(createSimpleWithdrawalUpdate(prefix, localPreference)));
197 checkLocRib(expectedRoutesOnDS);
200 void sendNotification(final BGPSessionImpl session) {
201 final Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode())
202 .setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
203 waitFutureSuccess(session.writeAndFlush(notMsg));
206 void causeBGPError(final BGPSessionImpl session) {
207 final Open openObj = new OpenBuilder().setBgpIdentifier(new Ipv4AddressNoZone("1.1.1.1"))
208 .setHoldTimer(Uint16.valueOf(50)).setMyAsNumber(Uint16.valueOf(72)).build();
209 waitFutureSuccess(session.writeAndFlush(openObj));
212 private void checkLocRib(final int expectedRoutesOnDS) throws Exception {
213 // FIXME: remove this sleep
215 readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
216 final Ipv4RoutesCase routes = (Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0)
219 if (routes != null) {
220 final Ipv4Routes routesCase = routes.getIpv4Routes();
221 if (routesCase != null) {
222 final List<Ipv4Route> routeList = routesCase.getIpv4Route();
223 size = routeList == null ? 0 : routeList.size();
231 Assert.assertEquals(expectedRoutesOnDS, size);
236 void checkPeersPresentOnDataStore(final int numberOfPeers) throws Exception {
237 readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
238 Assert.assertEquals(numberOfPeers, bgpRib.getRib().get(0).getPeer().size());
243 BGPSessionImpl createPeerSession(final Ipv4AddressNoZone peer, final BgpParameters bgpParameters,
244 final SimpleSessionListener sessionListener) throws InterruptedException {
245 return createPeerSession(peer, bgpParameters, sessionListener, AS_NUMBER);
248 BGPSessionImpl createPeerSession(final Ipv4AddressNoZone peer, final BgpParameters bgpParameters,
249 final SimpleSessionListener sessionListener,
250 final AsNumber remoteAsNumber) throws InterruptedException {
251 final StrictBGPPeerRegistry clientRegistry = new StrictBGPPeerRegistry();
252 final BGPDispatcherImpl clientDispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss,
253 this.worker, clientRegistry);
255 clientDispatchers.add(clientDispatcher);
256 clientRegistry.addPeer(new IpAddressNoZone(new Ipv4AddressNoZone(RIB_ID)), sessionListener,
257 new BGPSessionPreferences(remoteAsNumber, HOLDTIMER, new BgpId(peer),
258 AS_NUMBER, Lists.newArrayList(bgpParameters)));
260 return connectPeer(peer, clientDispatcher);
263 static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry, final Ipv4AddressNoZone peerAddress,
264 final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole,
265 final BGPPeerRegistry bgpPeerRegistry) {
266 return configurePeer(tableRegistry, peerAddress, ribImpl, bgpParameters, peerRole, bgpPeerRegistry,
267 AFI_SAFIS_ADVERTIZED, Collections.emptySet());
270 static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry,
271 final Ipv4AddressNoZone peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters,
272 final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry, final Set<TablesKey> afiSafiAdvertised,
273 final Set<TablesKey> gracefulAfiSafiAdvertised) {
274 final BgpPeer bgpPeer = Mockito.mock(BgpPeer.class);
275 doReturn(Optional.empty()).when(bgpPeer).getErrorHandling();
276 return configurePeer(tableRegistry, peerAddress, ribImpl, bgpParameters, peerRole, bgpPeerRegistry,
277 afiSafiAdvertised, gracefulAfiSafiAdvertised, Collections.emptyMap(), bgpPeer);
280 static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry, final Ipv4AddressNoZone peerAddress,
281 final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole,
282 final BGPPeerRegistry bgpPeerRegistry, final Set<TablesKey> afiSafiAdvertised,
283 final Set<TablesKey> gracefulAfiSafiAdvertised, final Map<TablesKey, Integer> llGracefulTimersAdvertised,
284 final BgpPeer peer) {
285 final IpAddressNoZone ipAddress = new IpAddressNoZone(peerAddress);
287 final BGPPeer bgpPeer = new BGPPeer(tableRegistry, new IpAddressNoZone(peerAddress), null, ribImpl, peerRole,
288 null, null, null, afiSafiAdvertised, gracefulAfiSafiAdvertised, llGracefulTimersAdvertised, peer);
289 final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
290 bgpPeerRegistry.addPeer(ipAddress, bgpPeer,
291 new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID), AS_NUMBER, tlvs));
292 bgpPeer.instantiateServiceInstance();
296 private static BGPSessionImpl connectPeer(final Ipv4Address localAddress, final BGPDispatcherImpl dispatcherImpl)
297 throws InterruptedException {
298 final Future<BGPSessionImpl> future = dispatcherImpl
299 .createClient(new InetSocketAddress(localAddress.getValue(), PORT.toJava()),
300 new InetSocketAddress(RIB_ID, PORT.toJava()), RETRY_TIMER, true);
302 waitFutureSuccess(future);
304 return future.getNow();
307 static BgpParameters createParameter(final boolean addPath) {
308 return createParameter(addPath, false, null);
311 static BgpParameters createParameter(final boolean addPath,
312 final boolean addIpv6,
313 final Map<TablesKey, Boolean> gracefulTables) {
314 final TablesKey ipv4Key = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
315 final List<TablesKey> advertisedTables = Lists.newArrayList(ipv4Key);
317 final TablesKey ipv6Key = new TablesKey(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
318 advertisedTables.add(ipv6Key);
320 final List<TablesKey> addPathTables = new ArrayList<>();
322 addPathTables.add(ipv4Key);
324 return PeerUtil.createBgpParameters(advertisedTables, addPathTables, gracefulTables, GRACEFUL_RESTART_TIME);
327 private static Update createSimpleUpdate(final Ipv4Prefix prefix, final PathId pathId,
328 final ClusterIdentifier clusterId, final long localPreference) {
329 final AttributesBuilder attBuilder = new AttributesBuilder();
330 attBuilder.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(localPreference)).build());
331 attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
332 attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
333 attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
334 if (clusterId != null) {
335 attBuilder.setClusterId(new ClusterIdBuilder().setCluster(Collections.singletonList(clusterId)).build());
336 attBuilder.setOriginatorId(new OriginatorIdBuilder()
337 .setOriginator(new Ipv4AddressNoZone(clusterId))
340 addAttributeAugmentation(attBuilder, prefix, pathId);
341 return new UpdateBuilder().setAttributes(attBuilder.build()).build();
344 private static Update createSimpleUpdateEbgp(final Ipv4Prefix prefix) {
345 final AttributesBuilder attBuilder = new AttributesBuilder();
346 attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
347 attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
348 new SegmentsBuilder().setAsSequence(Collections.singletonList(AS_NUMBER)).build())).build());
349 addAttributeAugmentation(attBuilder, prefix, null);
351 return new UpdateBuilder().setAttributes(attBuilder.build()).build();
354 private static void addAttributeAugmentation(final AttributesBuilder attBuilder, final Ipv4Prefix prefix,
355 final PathId pathId) {
356 attBuilder.setUnrecognizedAttributes(Collections.emptyList());
357 attBuilder.addAugmentation(Attributes1.class,
358 new Attributes1Builder().setMpReachNlri(
359 new MpReachNlriBuilder()
360 .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1)
362 .setAfi(Ipv4AddressFamily.class)
363 .setSafi(UnicastSubsequentAddressFamily.class)
364 .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
365 new DestinationIpv4CaseBuilder().setDestinationIpv4(
366 new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(
367 new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build()))
373 private static Update createSimpleWithdrawalUpdate(final Ipv4Prefix prefix, final long localPreference) {
374 final AttributesBuilder attBuilder = new AttributesBuilder();
375 attBuilder.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(localPreference)).build());
376 attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
377 attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
378 attBuilder.setUnrecognizedAttributes(Collections.emptyList());
379 return new UpdateBuilder()
380 .setWithdrawnRoutes(Collections.singletonList(new WithdrawnRoutesBuilder().setPrefix(prefix).build()))