Ejemplo n.º 1
0
  /** @throws InterruptedException on interruption */
  public final void testLinkStateUpdate() throws InterruptedException {
    TopologyMap graph1 = new TopologyMap(NODE_1);
    // cause timestamp-based sequence numbers to be different
    Thread.sleep(SHORT_TIMESTAMP_CHANGING_DELAY);
    TopologyMap graph2 = new TopologyMap(NODE_2);
    // crude approach to ensure different timestamps; it would be better to inject an artificial
    // time source for testing -- misc_ro, June 2013
    while (graph2.getSequenceNumberOfNode(NODE_2) == graph1.getSequenceNumberOfNode(NODE_1)) {
      Thread.sleep(SHORT_TIMESTAMP_CHANGING_DELAY);
      graph2 = new TopologyMap(NODE_2);
    }

    // get the highest current sequence number (assuming node 3 was assigned the highest one)
    long node1OriginalSeqNo = graph1.getSequenceNumberOfNode(NODE_1);
    long node2OriginalSeqNo = graph2.getSequenceNumberOfNode(NODE_2);

    assertFalse(node1OriginalSeqNo == node2OriginalSeqNo);
    assertFalse(graph1.equals(graph2));

    LinkStateAdvertisement lsa = graph1.generateNewLocalLSA();

    // LSA generation should have increased the node 1 sequence number in graph 1
    long node1NewSeqNo = graph1.getSequenceNumberOfNode(NODE_1);
    assertEquals(node1NewSeqNo, lsa.getSequenceNumber());
    assertTrue(node1NewSeqNo > node1OriginalSeqNo);

    // verify graph update
    assertTrue(graph2.update(lsa));
    assertEquals(node1NewSeqNo, graph2.getSequenceNumberOfNode(NODE_1));

    lsa = graph2.generateNewLocalLSA();

    // LSA generation should have increased the node 2 sequence number in graph 2
    long node2NewSeqNo = graph2.getSequenceNumberOfNode(NODE_2);
    assertEquals(node2NewSeqNo, lsa.getSequenceNumber());
    assertTrue(node2NewSeqNo > node2OriginalSeqNo);

    // verify graph update
    assertTrue(graph1.update(lsa));
    assertEquals(node2NewSeqNo, graph1.getSequenceNumberOfNode(NODE_2));

    assertTrue(graph1.equals(graph2));

    graph1.addNode(NODE_3);
    graph1.addLink(NODE_1, NODE_3, CONNECTION_ID_1);

    assertFalse(graph1.equals(graph2));

    lsa = graph1.generateNewLocalLSA();
    assertTrue(lsa.getSequenceNumber() > node1NewSeqNo);
    node1NewSeqNo = graph1.getSequenceNumberOfNode(NODE_1);
    assertEquals(node1NewSeqNo, lsa.getSequenceNumber());

    assertTrue(graph2.update(lsa));
    assertEquals(node1NewSeqNo, graph2.getSequenceNumberOfNode(NODE_1));
    assertTrue(graph1.equals(graph2));

    graph2.addLink(NODE_2, NODE_1, CONNECTION_ID_1);

    assertFalse(graph2.equals(graph1));

    lsa = graph2.generateNewLocalLSA();
    graph1.update(lsa);

    node2NewSeqNo = graph2.getSequenceNumberOfNode(NODE_2);
    assertEquals(node2NewSeqNo, lsa.getSequenceNumber());

    assertTrue(graph2.equals(graph1));
    assertEquals(node1NewSeqNo, graph2.getSequenceNumberOfNode(NODE_1));
    assertEquals(node2NewSeqNo, graph2.getSequenceNumberOfNode(NODE_2));
    assertEquals(graph1.getSequenceNumberOfNode(NODE_3), graph2.getSequenceNumberOfNode(NODE_3));

    // log.info(NetworkFormatter.summary(graph2));
    // log.info(NetworkFormatter.summary(graph1));
  }
Ejemplo n.º 2
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));
  }