Exemple #1
0
  /** Test graph updates with different {@link LinkStateAdvertisement}s. */
  public final void testLsaIntegration1() {
    networkGraph = new TopologyMap(NODE_1);

    networkGraph.addNode(NODE_2);

    networkGraph.addLink(NODE_1, NODE_2, CONNECTION_ID_1);

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_2));

    LinkStateAdvertisement linkStateAdvertisement =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_2,
            NODE_2_NAME,
            true,
            ARBITRARY_INT,
            networkGraph.hashCode(),
            true,
            Arrays.asList(
                new TopologyLink[] {
                  new TopologyLink(NODE_2, NODE_1, CONNECTION_ID_1),
                  new TopologyLink(NODE_2, NODE_3, CONNECTION_ID_1)
                }));

    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(linkStateAdvertisement));

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_1));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_2));
  }
Exemple #2
0
  /** Test for {@link TopologyMap#getAllLinks()}. */
  public final void testGetChannels() {
    networkGraph = new TopologyMap(NODE_1);

    networkGraph.addNode(NODE_1);
    networkGraph.addNode(NODE_2);
    networkGraph.addNode(NODE_3);

    networkGraph.addLink(NODE_1, NODE_2, CONNECTION_ID_1);
    networkGraph.addLink(NODE_2, NODE_1, CONNECTION_ID_1);
    networkGraph.addLink(NODE_2, NODE_3, CONNECTION_ID_1);

    assertEquals(3, networkGraph.getAllLinks().size());

    assertNotNull(networkGraph.getLinkForConnection(CONNECTION_ID_1));
    assertEquals(
        networkGraph.getLinkForConnection(CONNECTION_ID_1),
        new TopologyLink(NODE_1, NODE_2, CONNECTION_ID_1));

    networkGraph.removeLink(null);
    networkGraph.removeLink(networkGraph.getLinkForConnection(CONNECTION_ID_1));

    assertEquals(2, networkGraph.getAllLinks().size());
    assertFalse(networkGraph.containsLinkBetween(NODE_1, NODE_2));
    assertFalse(networkGraph.containsLink(NODE_1, NODE_2, CONNECTION_ID_1));
  }
Exemple #3
0
  /**
   * Tests for {@link NetworkGraph#containsAnyChannel(NodeIdentifier, NodeIdentifier).
   */
  public final void testContainsAnyChannel() {
    networkGraph = new TopologyMap(NODE_5);

    // TODO review this test; some of it seem redundant

    assertFalse(networkGraph.containsLinkBetween(null, null));
    assertFalse(networkGraph.containsLinkBetween(NODE_5, null));
    assertFalse(networkGraph.containsLinkBetween(NODE_1, null));
    assertFalse(networkGraph.containsLinkBetween(null, NODE_5));
    assertFalse(networkGraph.containsLinkBetween(null, NODE_1));

    networkGraph.addLink(NODE_1, NODE_5, CONNECTION_ID_1);
    // TODO review: changed to assertTrue() after switch to connection ids; why was this
    // assertFalse() before? -- misc_ro
    assertTrue(networkGraph.containsLinkBetween(NODE_1, NODE_5));

    networkGraph.addNode(NODE_1);

    assertTrue(networkGraph.containsLink(NODE_1, NODE_5, CONNECTION_ID_1));
    assertFalse(networkGraph.containsLink(NODE_1, NODE_5, CONNECTION_ID_2));
  }
Exemple #4
0
  /** Test graph updates with different {@link LinkStateAdvertisement}s. */
  public final void testSequenceNumberUpdate() {
    networkGraph = new TopologyMap(NODE_1);

    LinkStateAdvertisement linkStateAdvertisement =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_2,
            NODE_2_NAME,
            true,
            ARBITRARY_INT,
            networkGraph.hashCode(),
            true,
            Arrays.asList(
                new TopologyLink[] {
                  new TopologyLink(NODE_2, NODE_1, CONNECTION_ID_1),
                  new TopologyLink(NODE_2, NODE_3, CONNECTION_ID_1)
                }));

    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(linkStateAdvertisement));

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_1));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));

    // this should be ignored, because the sequence number is to small/old
    linkStateAdvertisement =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_2,
            NODE_2_NAME,
            true,
            ARBITRARY_INT - 1,
            networkGraph.hashCode(),
            true,
            Arrays.asList(new TopologyLink[] {}));

    assertFalse(LSA_CAUSED_UPDATE, networkGraph.update(linkStateAdvertisement));

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_1));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));
  }
Exemple #5
0
  /** Simple test for graph setup: NODE_1 - NODE_2 - NODE_3. */
  public final void testGraphSetUp() {
    networkGraph = new TopologyMap(NODE_1);

    networkGraph.addNode(NODE_1);
    networkGraph.addNode(NODE_2);
    networkGraph.addNode(NODE_3);

    assertTrue(GRAPH_CONTAINS_NODE, networkGraph.containsNode(NODE_1));
    assertTrue(GRAPH_CONTAINS_NODE, networkGraph.containsNode(NODE_2));
    assertTrue(GRAPH_CONTAINS_NODE, networkGraph.containsNode(NODE_3));
    assertFalse(GRAPH_DOES_NOT_CONTAIN_NODE, networkGraph.containsNode(NODE_4));
    assertFalse(GRAPH_DOES_NOT_CONTAIN_NODE, networkGraph.containsNode(NODE_5));

    networkGraph.addLink(NODE_1, NODE_2, CONNECTION_ID_1);
    networkGraph.addLink(NODE_2, NODE_3, CONNECTION_ID_1);

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_2));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));
    assertFalse(GRAPH_CONTAINS_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_3));
    assertFalse(GRAPH_CONTAINS_CHANNEL, networkGraph.containsLinkBetween(NODE_4, NODE_5));
    assertEquals(DIFFERENT_NUMBER_OF_EDGES_IN_GRAPH_EXPECTED, 2, networkGraph.getLinkCount());
    assertEquals(DIFFERENT_NUMBER_OF_VERTICES_IN_GRAPH_EXPECTED, 3, networkGraph.getNodeCount());
  }
Exemple #6
0
  /** Build graph and do manipulations with some {@link LinkStateAdvertisement}s. */
  public final void testEmptyGraphUpdate() {
    networkGraph = new TopologyMap(NODE_1);

    LinkStateAdvertisement linkStateAdvertisement =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_2,
            NODE_2_NAME,
            true,
            ARBITRARY_INT,
            networkGraph.hashCode(),
            true,
            Arrays.asList(
                new TopologyLink[] {
                  new TopologyLink(NODE_2, NODE_1, CONNECTION_ID_1),
                  new TopologyLink(NODE_2, NODE_3, CONNECTION_ID_1)
                }));

    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(linkStateAdvertisement));

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_1));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));

    linkStateAdvertisement =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_2,
            NODE_2_NAME,
            true,
            ARBITRARY_INT + 1,
            networkGraph.hashCode(),
            true,
            Arrays.asList(new TopologyLink[] {}));

    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(linkStateAdvertisement));

    assertEquals(DIFFERENT_NUMBER_OF_EDGES_IN_GRAPH_EXPECTED, 0, networkGraph.getLinkCount());
    assertEquals(DIFFERENT_NUMBER_OF_VERTICES_IN_GRAPH_EXPECTED, 3, networkGraph.getNodeCount());
  }
Exemple #7
0
  /** Build graph and do manipulations with some {@link LinkStateAdvertisement}s. */
  public final void testUpdateGraph() {
    // IMPORTANT: the test graph must be "owned" by a node that is not used in the test,
    // as TopologyMap was made to ignore external updates for its local node
    networkGraph = new TopologyMap(NODE_3);

    networkGraph.addNode(NODE_1);
    networkGraph.addNode(NODE_2);
    networkGraph.addNode(NODE_3);

    assertFalse(GRAPH_CONTAINS_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_3));
    assertFalse(GRAPH_CONTAINS_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_2));
    assertFalse(GRAPH_CONTAINS_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));

    networkGraph.addLink(NODE_1, NODE_2, CONNECTION_ID_1);
    networkGraph.addLink(NODE_2, NODE_3, CONNECTION_ID_2);

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_2));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));
    assertFalse(GRAPH_CONTAINS_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_3));

    LinkStateAdvertisement lsa =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_1,
            NODE_1_NAME,
            true,
            networkGraph.getSequenceNumberOfNode(NODE_1) + 1,
            networkGraph.hashCode(),
            true,
            Arrays.asList(
                new TopologyLink[] {
                  new TopologyLink(NODE_1, NODE_2, CONNECTION_ID_1),
                  new TopologyLink(NODE_1, NODE_3, CONNECTION_ID_3)
                }));

    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(lsa));

    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_3));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_2));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_2, NODE_3));

    lsa =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_1,
            NODE_1_NAME,
            true,
            networkGraph.getSequenceNumberOfNode(NODE_1) + 1,
            networkGraph.hashCode(),
            true,
            Arrays.asList(new TopologyLink[] {new TopologyLink(NODE_1, NODE_3, CONNECTION_ID_1)}));

    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(lsa));

    assertFalse(GRAPH_CONTAINS_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_2));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_1, NODE_3));

    // inject a new node (NODE_4) via LSA
    lsa =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_4,
            NODE_4_NAME,
            true,
            1,
            networkGraph.hashCode(),
            true,
            Arrays.asList(
                new TopologyLink[] {
                  new TopologyLink(NODE_4, NODE_3, CONNECTION_ID_1),
                  new TopologyLink(NODE_4, NODE_2, CONNECTION_ID_1)
                }));

    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(lsa));

    assertTrue(GRAPH_CONTAINS_NODE, networkGraph.containsNode(NODE_4));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_4, NODE_3));

    lsa =
        LinkStateAdvertisement.createUpdateLsa(
            NODE_4,
            NODE_4_NAME,
            true,
            networkGraph.getSequenceNumberOfNode(NODE_4) + 1,
            networkGraph.hashCode(),
            true,
            Arrays.asList(new TopologyLink[] {new TopologyLink(NODE_4, NODE_5, CONNECTION_ID_1)}));

    assertFalse(GRAPH_DOES_NOT_CONTAIN_NODE, networkGraph.containsNode(NODE_5));

    // log.info(NetworkFormatter.summary(networkGraph));
    assertTrue(LSA_CAUSED_NO_UPDATE, networkGraph.update(lsa));

    assertTrue(GRAPH_CONTAINS_NODE, networkGraph.containsNode(NODE_5));
    assertTrue(GRAPH_SHOULD_CONTAIN_CHANNEL, networkGraph.containsLinkBetween(NODE_4, NODE_5));
  }