Example #1
0
  @Before
  public void setUp() throws Exception {
    idGenerator = new TestIdGenerator();
    Intent.bindIdGenerator(idGenerator);

    applicationService = createMock(ApplicationService.class);

    coreService = createMock(CoreService.class);
    expect(coreService.registerApplication(APP_NAME)).andReturn(APPID);
    replay(coreService);

    hostsAvailable = Sets.newHashSet();
    hostService = new TestHostService(hostsAvailable);

    intentService = new TestIntentService();

    TestIntentSynchronizer intentSynchronizer = new TestIntentSynchronizer(intentService);

    interfaceService = createMock(InterfaceService.class);
    interfaceService.addListener(anyObject(InterfaceListener.class));
    expectLastCall().anyTimes();
    addIntfConfig();

    vpls = new Vpls();
    vpls.applicationService = applicationService;
    vpls.coreService = coreService;
    vpls.hostService = hostService;
    vpls.intentService = intentService;
    vpls.interfaceService = interfaceService;
    vpls.intentSynchronizer = intentSynchronizer;
  }
  /** Tests a corner case, when there are no interfaces in the configuration. */
  @Test
  public void testNullInterfaces() {
    reset(interfaceService);
    interfaceService.addListener(anyObject(InterfaceListener.class));
    expectLastCall().anyTimes();

    expect(interfaceService.getInterfaces()).andReturn(Sets.newHashSet()).anyTimes();
    expect(interfaceService.getInterfacesByPort(s2Eth1))
        .andReturn(Collections.emptySet())
        .anyTimes();
    expect(interfaceService.getInterfacesByPort(s1Eth1))
        .andReturn(Collections.emptySet())
        .anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101")))
        .andReturn(Collections.emptySet())
        .anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1")))
        .andReturn(null)
        .anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101")))
        .andReturn(Collections.emptySet())
        .anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1")))
        .andReturn(null)
        .anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101")))
        .andReturn(Collections.emptySet())
        .anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1")))
        .andReturn(null)
        .anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.40.101")))
        .andReturn(Collections.emptySet())
        .anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.40.1")))
        .andReturn(null)
        .anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.50.101")))
        .andReturn(Collections.emptySet())
        .anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.50.1")))
        .andReturn(null)
        .anyTimes();

    replay(interfaceService);

    reset(intentSynchronizer);
    replay(intentSynchronizer);
    peerConnectivityManager.start();
    verify(intentSynchronizer);
  }
  /** Tests a corner case, when there is no Interface configured for one BGP peer. */
  @Test
  public void testNoPeerInterface() {
    IpAddress ip = IpAddress.valueOf("1.1.1.1");
    bgpSpeakers.clear();
    bgpSpeakers.add(
        new BgpConfig.BgpSpeakerConfig(
            Optional.of("foo"), VlanId.NONE, s1Eth100, Collections.singleton(ip)));
    reset(interfaceService);
    interfaceService.addListener(anyObject(InterfaceListener.class));
    expect(interfaceService.getMatchingInterface(ip)).andReturn(null).anyTimes();
    replay(interfaceService);

    // We don't expect any intents in this case
    reset(intentSynchronizer);
    replay(intentSynchronizer);
    peerConnectivityManager.start();
    verify(intentSynchronizer);
  }
  @Before
  public void setUp() throws Exception {
    super.setUp();

    interfaceService = createMock(InterfaceService.class);
    interfaceService.addListener(anyObject(InterfaceListener.class));
    expectLastCall().anyTimes();
    networkConfigService = createMock(NetworkConfigService.class);
    networkConfigService.addListener(anyObject(NetworkConfigListener.class));
    expectLastCall().anyTimes();
    bgpConfig = createMock(BgpConfig.class);

    // These will set expectations on routingConfig and interfaceService
    bgpSpeakers = setUpBgpSpeakers();
    interfaces = Collections.unmodifiableMap(setUpInterfaces());

    initPeerConnectivity();
    intentList = setUpIntentList();
  }