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