Search in sources :

Example 1 with LispRouter

use of org.onosproject.lisp.ctl.LispRouter in project onos by opennetworkinglab.

the class LispMapServer method sendSmrMessage.

/**
 * Sends SMR (Solicit Map Request) to their subscribers.
 *
 * @param eidRecord the updated EID
 */
private void sendSmrMessage(LispEidRecord eidRecord) {
    RequestBuilder builder = new DefaultRequestBuilder();
    LispAfiAddress msAddress = null;
    try {
        msAddress = new LispIpv4Address(IpAddress.valueOf(InetAddress.getLocalHost()));
    } catch (UnknownHostException e) {
        log.warn("Source EID is not found, {}", e.getMessage());
    }
    LispMapRequest msg = builder.withIsSmr(true).withIsSmrInvoked(true).withIsProbe(false).withIsPitr(false).withIsAuthoritative(false).withIsMapDataPresent(false).withSourceEid(msAddress).withEidRecords(ImmutableList.of(eidRecord)).build();
    LispRouterFactory routerFactory = LispRouterFactory.getInstance();
    Collection<LispRouter> routers = routerFactory.getRouters();
    routers.forEach(router -> {
        if (isInEidRecordRange(eidRecord, router.getEidRecords())) {
            router.sendMessage(msg);
        }
    });
}
Also used : LispRouter(org.onosproject.lisp.ctl.LispRouter) DefaultRequestBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.DefaultRequestBuilder) RequestBuilder(org.onosproject.lisp.msg.protocols.LispMapRequest.RequestBuilder) InfoRequestBuilder(org.onosproject.lisp.msg.protocols.LispInfoRequest.InfoRequestBuilder) DefaultInfoRequestBuilder(org.onosproject.lisp.msg.protocols.DefaultLispInfoRequest.DefaultInfoRequestBuilder) UnknownHostException(java.net.UnknownHostException) LispIpv4Address(org.onosproject.lisp.msg.types.LispIpv4Address) LispRouterFactory(org.onosproject.lisp.ctl.LispRouterFactory) DefaultRequestBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.DefaultRequestBuilder) LispAfiAddress(org.onosproject.lisp.msg.types.LispAfiAddress) LispMapRequest(org.onosproject.lisp.msg.protocols.LispMapRequest)

Example 2 with LispRouter

use of org.onosproject.lisp.ctl.LispRouter in project onos by opennetworkinglab.

the class LispControllerImplTest method testAddRemoveConnectedRouter.

/**
 * Tests adding and removing connected routers.
 */
@Test
public void testAddRemoveConnectedRouter() {
    // Test adding connected routers into agent
    boolean addRouter1 = agent.addConnectedRouter(routerId1, router1);
    assertThat(addRouter1, is(true));
    boolean addRouter2 = agent.addConnectedRouter(routerId2, router2);
    assertThat(addRouter2, is(true));
    boolean addRouter3 = agent.addConnectedRouter(routerId3, router3);
    assertThat(addRouter3, is(true));
    // Test the callback methods that contained in router listener is fired
    assertThat(routerListener.addedIds, hasSize(3));
    assertThat(routerListener.addedIds, hasItems(routerId1, routerId2, routerId3));
    // Test adding a router twice (duplicated router)
    // this should return false to indicate that there is already a router
    // has been added previously
    boolean addBadRouter1 = agent.addConnectedRouter(routerId1, router1);
    assertThat(addBadRouter1, is(false));
    // Also make sure that the duplicated router will never increase the counter
    assertThat(controller.connectedRouters.size(), is(3));
    // Test querying the router list
    Stream<LispRouter> queriedRouters = makeIntoStream(controller.getRouters());
    long routerCount = queriedRouters.count();
    assertThat(routerCount, is(3L));
    // Test querying the individual router
    LispRouter queriedRouter = controller.getRouter(routerId1);
    assertThat(queriedRouter, is(router1));
    // Test removing a router from connected router collection
    agent.removeConnectedRouter(routerId2);
    Stream<LispRouter> queriedRoutersAfterRemoval = makeIntoStream(controller.getRouters());
    long routerCountAfterRemoval = queriedRoutersAfterRemoval.count();
    assertThat(routerCountAfterRemoval, is(2L));
    // Test the callback methods that contained in router listener is fired
    assertThat(routerListener.removedIds, hasSize(1));
    assertThat(routerListener.removedIds, hasItems(routerId2));
    // Test querying the removed switch
    LispRouter queriedRouterAfterRemoval = controller.getRouter(routerId2);
    assertThat(queriedRouterAfterRemoval, nullValue());
}
Also used : LispRouter(org.onosproject.lisp.ctl.LispRouter) Test(org.junit.Test)

Aggregations

LispRouter (org.onosproject.lisp.ctl.LispRouter)2 UnknownHostException (java.net.UnknownHostException)1 Test (org.junit.Test)1 LispRouterFactory (org.onosproject.lisp.ctl.LispRouterFactory)1 DefaultInfoRequestBuilder (org.onosproject.lisp.msg.protocols.DefaultLispInfoRequest.DefaultInfoRequestBuilder)1 DefaultRequestBuilder (org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.DefaultRequestBuilder)1 InfoRequestBuilder (org.onosproject.lisp.msg.protocols.LispInfoRequest.InfoRequestBuilder)1 LispMapRequest (org.onosproject.lisp.msg.protocols.LispMapRequest)1 RequestBuilder (org.onosproject.lisp.msg.protocols.LispMapRequest.RequestBuilder)1 LispAfiAddress (org.onosproject.lisp.msg.types.LispAfiAddress)1 LispIpv4Address (org.onosproject.lisp.msg.types.LispIpv4Address)1