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