54274e4d1e190e733129b48b0c9b9f03b27e388c
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / AbstractAddPathTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
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;
14
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.Collections;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.concurrent.ExecutionException;
26 import java.util.concurrent.TimeUnit;
27 import org.junit.After;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
33 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
34 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
35 import org.opendaylight.protocol.bgp.inet.RIBActivator;
36 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
37 import org.opendaylight.protocol.bgp.parser.BGPError;
38 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
39 import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
40 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
41 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
42 import org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer;
43 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
44 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
45 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
46 import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
47 import org.opendaylight.protocol.util.InetSocketAddressUtil;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.Ipv4Routes;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route;
57 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;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AsPathBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterIdBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPrefBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.as.path.SegmentsBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.update.message.WithdrawnRoutesBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpId;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpOrigin;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
89 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;
90 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
91 import org.opendaylight.yangtools.yang.binding.Notification;
92
93 public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest {
94     private static final int RETRY_TIMER = 10;
95     static final String RIB_ID = "127.0.0.1";
96     static final BgpId BGP_ID = new BgpId(RIB_ID);
97     static final Ipv4Address PEER1 = new Ipv4Address("127.0.0.2");
98     static final Ipv4Address PEER2 = new Ipv4Address("127.0.0.3");
99     static final Ipv4Address PEER3 = new Ipv4Address("127.0.0.4");
100     static final Ipv4Address PEER4 = new Ipv4Address("127.0.0.5");
101     static final Ipv4Address PEER5 = new Ipv4Address("127.0.0.6");
102     static final Ipv4Address PEER6 = new Ipv4Address("127.0.0.7");
103     static final AsNumber AS_NUMBER = new AsNumber(AS);
104     static final int PORT = InetSocketAddressUtil.getRandomPort();
105     static final Ipv4Prefix PREFIX1 = new Ipv4Prefix("1.1.1.1/32");
106     private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier(RIB_ID);
107     static final int HOLDTIMER = 2180;
108     private static final Ipv4Address NH1 = new Ipv4Address("2.2.2.2");
109     static final Update UPD_100 = createSimpleUpdate(PREFIX1, new PathId(1L), CLUSTER_ID, 100);
110     static final Update UPD_50 = createSimpleUpdate(PREFIX1, new PathId(2L), CLUSTER_ID, 50);
111     static final Update UPD_200 = createSimpleUpdate(PREFIX1, new PathId(3L), CLUSTER_ID, 200);
112     static final Update UPD_20 = createSimpleUpdate(PREFIX1, new PathId(1L), CLUSTER_ID, 20);
113     static final Update UPD_NA_100 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 100);
114     static final Update UPD_NA_100_EBGP = createSimpleUpdateEbgp(PREFIX1);
115     static final Update UPD_NA_200 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 200);
116     static final Update UPD_NA_200_EBGP = createSimpleUpdateEbgp(PREFIX1);
117     static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
118     static final List<BgpTableType> TABLES_TYPE = ImmutableList.of(new BgpTableTypeImpl(TABLES_KEY.getAfi(),
119         TABLES_KEY.getSafi()));
120     static final Set<TablesKey> AFI_SAFIS_ADVERTIZED = Collections.singleton(TABLES_KEY);
121     private BGPExtensionProviderContext context;
122     static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
123     static final int GRACEFUL_RESTART_TIME = 5;
124     @Mock
125     protected ClusterSingletonServiceProvider clusterSingletonServiceProvider;
126     BGPDispatcherImpl serverDispatcher;
127     RIBExtensionProviderContext ribExtension;
128     private RIBActivator ribActivator;
129     private BGPActivator bgpActivator;
130     private NioEventLoopGroup worker;
131     private NioEventLoopGroup boss;
132     private org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator;
133     protected StrictBGPPeerRegistry serverRegistry;
134     protected CodecsRegistryImpl codecsRegistry;
135
136     @Override
137     @Before
138     public void setUp() throws Exception {
139         super.setUp();
140         this.ribActivator = new RIBActivator();
141         this.ribExtension = new SimpleRIBExtensionProviderContext();
142
143         this.ribActivator.startRIBExtensionProvider(this.ribExtension, this.mappingService);
144
145         this.bgpActivator = new BGPActivator();
146         this.inetActivator = new org.opendaylight.protocol.bgp.inet.BGPActivator();
147         this.context = new SimpleBGPExtensionProviderContext();
148         this.bgpActivator.start(this.context);
149         this.inetActivator.start(this.context);
150         if (!Epoll.isAvailable()) {
151             this.worker = new NioEventLoopGroup();
152             this.boss = new NioEventLoopGroup();
153         }
154         this.serverRegistry = new StrictBGPPeerRegistry();
155         this.serverDispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss, this.worker,
156             this.serverRegistry);
157         doReturn(Mockito.mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
158             .registerClusterSingletonService(any(ClusterSingletonService.class));
159
160         this.codecsRegistry = CodecsRegistryImpl.create(this.mappingService.getCodecFactory(),
161                 this.ribExtension.getClassLoadingStrategy());
162     }
163
164     @Override
165     @After
166     public void tearDown() throws ExecutionException, InterruptedException {
167         this.serverDispatcher.close();
168         if (!Epoll.isAvailable()) {
169             this.worker.shutdownGracefully(0, 0, TimeUnit.SECONDS);
170             this.boss.shutdownGracefully(0, 0, TimeUnit.SECONDS);
171         }
172         this.mappingService.close();
173         this.ribActivator.close();
174         this.inetActivator.close();
175         this.bgpActivator.close();
176     }
177
178     void sendRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference,
179         final int expectedRoutesOnDS) throws Exception {
180         waitFutureSuccess(session.writeAndFlush(createSimpleUpdate(prefix, null, null, localPreference)));
181         checkLocRib(expectedRoutesOnDS);
182     }
183
184     void sendWithdrawalRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix,
185         final long localPreference, final int expectedRoutesOnDS) throws Exception {
186         waitFutureSuccess(session.writeAndFlush(createSimpleWithdrawalUpdate(prefix, localPreference)));
187         checkLocRib(expectedRoutesOnDS);
188     }
189
190     void sendNotification(final BGPSessionImpl session) {
191         final Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode())
192             .setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
193         waitFutureSuccess(session.writeAndFlush(notMsg));
194     }
195
196     void causeBGPError(final BGPSessionImpl session) {
197         final Open openObj = new OpenBuilder().setBgpIdentifier(new Ipv4Address("1.1.1.1"))
198             .setHoldTimer(50).setMyAsNumber(72).build();
199         waitFutureSuccess(session.writeAndFlush(openObj));
200     }
201
202     private void checkLocRib(final int expectedRoutesOnDS) throws Exception {
203         // FIXME: remove this sleep
204         Thread.sleep(100);
205         readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
206             final Ipv4RoutesCase routes = (Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0)
207                 .getRoutes();
208             final int size;
209             if (routes != null) {
210                 final Ipv4Routes routesCase = routes.getIpv4Routes();
211                 if (routesCase != null) {
212                     final List<Ipv4Route> routeList = routesCase.getIpv4Route();
213                     size = routeList == null ? 0 : routeList.size();
214                 } else {
215                     size = 0;
216                 }
217             } else {
218                 size = 0;
219             }
220
221             Assert.assertEquals(expectedRoutesOnDS, size);
222             return bgpRib;
223         });
224     }
225
226     void checkPeersPresentOnDataStore(final int numberOfPeers) throws Exception {
227         readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
228             Assert.assertEquals(numberOfPeers, bgpRib.getRib().get(0).getPeer().size());
229             return bgpRib;
230         });
231     }
232
233     BGPSessionImpl createPeerSession(final Ipv4Address peer, final BgpParameters bgpParameters,
234         final SimpleSessionListener sessionListener) throws InterruptedException {
235         final StrictBGPPeerRegistry clientRegistry = new StrictBGPPeerRegistry();
236         final BGPDispatcherImpl clientDispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss,
237             this.worker, clientRegistry);
238         clientRegistry.addPeer(new IpAddress(new Ipv4Address(RIB_ID)), sessionListener,
239             new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(peer),
240                 AS_NUMBER, Lists.newArrayList(bgpParameters)));
241
242         return connectPeer(peer, clientDispatcher);
243     }
244
245     static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry,
246                                  final Ipv4Address peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters,
247                                  final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry) {
248         return configurePeer(tableRegistry, peerAddress, ribImpl, bgpParameters, peerRole, bgpPeerRegistry,
249                 AFI_SAFIS_ADVERTIZED, Collections.emptySet());
250     }
251
252     static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry,
253             final Ipv4Address peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters,
254             final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry, final Set<TablesKey> afiSafiAdvertised,
255             final Set<TablesKey> gracefulAfiSafiAdvertised) {
256         return configurePeer(tableRegistry, peerAddress, ribImpl, bgpParameters, peerRole, bgpPeerRegistry,
257                 afiSafiAdvertised, gracefulAfiSafiAdvertised, null);
258     }
259
260     static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry,
261                                  final Ipv4Address peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters,
262                                  final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry,
263                                  final Set<TablesKey> afiSafiAdvertised, final Set<TablesKey> gracefulAfiSafiAdvertised,
264                                  final BgpPeer peer) {
265         final IpAddress ipAddress = new IpAddress(peerAddress);
266
267         final BGPPeer bgpPeer = new BGPPeer(tableRegistry, new IpAddress(peerAddress), null, ribImpl, peerRole,
268                 null, null, null, afiSafiAdvertised, gracefulAfiSafiAdvertised, peer);
269         final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
270         bgpPeerRegistry.addPeer(ipAddress, bgpPeer,
271                 new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID), AS_NUMBER, tlvs));
272         bgpPeer.instantiateServiceInstance();
273         return bgpPeer;
274     }
275
276     private static BGPSessionImpl connectPeer(final Ipv4Address localAddress, final BGPDispatcherImpl dispatcherImpl)
277             throws InterruptedException {
278         final Future<BGPSessionImpl> future = dispatcherImpl
279                 .createClient(new InetSocketAddress(localAddress.getValue(), PORT),
280                         new InetSocketAddress(RIB_ID, PORT), RETRY_TIMER, true);
281         Thread.sleep(200);
282         waitFutureSuccess(future);
283         Thread.sleep(100);
284         return future.getNow();
285     }
286
287     static BgpParameters createParameter(final boolean addPath) {
288         return createParameter(addPath, false, null);
289     }
290
291     static BgpParameters createParameter(final boolean addPath,
292                                          final boolean addIpv6,
293                                          final Map<TablesKey, Boolean> gracefulTables) {
294         final TablesKey ipv4Key = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
295         final List<TablesKey> advertisedTables = Lists.newArrayList(ipv4Key);
296         if (addIpv6) {
297             final TablesKey ipv6Key = new TablesKey(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
298             advertisedTables.add(ipv6Key);
299         }
300         final List<TablesKey> addPathTables = Lists.newArrayList();
301         if (addPath) {
302             addPathTables.add(ipv4Key);
303         }
304         return PeerUtil.createBgpParameters(advertisedTables, addPathTables, gracefulTables, GRACEFUL_RESTART_TIME);
305     }
306
307     private static Update createSimpleUpdate(final Ipv4Prefix prefix, final PathId pathId,
308             final ClusterIdentifier clusterId, final long localPreference) {
309         final AttributesBuilder attBuilder = new AttributesBuilder();
310         attBuilder.setLocalPref(new LocalPrefBuilder().setPref(localPreference).build());
311         attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
312         attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
313         attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(0L).build());
314         if (clusterId != null) {
315             attBuilder.setClusterId(new ClusterIdBuilder().setCluster(Collections.singletonList(clusterId)).build());
316             attBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address(clusterId)).build());
317         }
318         addAttributeAugmentation(attBuilder, prefix, pathId);
319         return new UpdateBuilder().setAttributes(attBuilder.build()).build();
320     }
321
322     private static Update createSimpleUpdateEbgp(final Ipv4Prefix prefix) {
323         final AttributesBuilder attBuilder = new AttributesBuilder();
324         attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
325         attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
326             new SegmentsBuilder().setAsSequence(Collections.singletonList(AS_NUMBER)).build())).build());
327         addAttributeAugmentation(attBuilder, prefix, null);
328
329         return new UpdateBuilder().setAttributes(attBuilder.build()).build();
330     }
331
332     private static void addAttributeAugmentation(final AttributesBuilder attBuilder, final Ipv4Prefix prefix,
333         final PathId pathId) {
334         attBuilder.setUnrecognizedAttributes(Collections.emptyList());
335         attBuilder.addAugmentation(Attributes1.class,
336             new Attributes1Builder().setMpReachNlri(
337                 new MpReachNlriBuilder()
338                     .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1)
339                         .build()).build())
340                     .setAfi(Ipv4AddressFamily.class)
341                     .setSafi(UnicastSubsequentAddressFamily.class)
342                     .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
343                         new DestinationIpv4CaseBuilder().setDestinationIpv4(
344                             new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(
345                                 new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build()))
346                                 .build())
347                             .build()).build())
348                     .build()).build());
349     }
350
351     private static Update createSimpleWithdrawalUpdate(final Ipv4Prefix prefix, final long localPreference) {
352         final AttributesBuilder attBuilder = new AttributesBuilder();
353         attBuilder.setLocalPref(new LocalPrefBuilder().setPref(localPreference).build());
354         attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
355         attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
356         attBuilder.setUnrecognizedAttributes(Collections.emptyList());
357         return new UpdateBuilder()
358                 .setWithdrawnRoutes(Collections.singletonList(new WithdrawnRoutesBuilder().setPrefix(prefix).build()))
359                 .build();
360     }
361 }