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