Guest User

Untitled

a guest
Jan 5th, 2016
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.36 KB | None | 0 0
  1.     private void topologySetTest(DataBroker dataBroker) {
  2.         final InstanceIdentifier<Network> NETWORK_IID =
  3.                 InstanceIdentifier.builder(Network.class, new NetworkKey(new NetworkId("test-network"))).build();
  4.  
  5.         LOG.info("*** topologySetTest started");
  6.        
  7.         LOG.info("*** Writing plain node");
  8.  
  9.         NodeKey key1 = new NodeKey(new NodeId("cvok1"));
  10.         Node node1 = new NodeBuilder()
  11.                     .setKey(key1)
  12.                     .build();
  13.        
  14.         WriteTransaction tx1 = dataBroker.newWriteOnlyTransaction();
  15.         InstanceIdentifier<Node> node_IID1 = NETWORK_IID.child(Node.class, key1);
  16.         tx1.put(LogicalDatastoreType.CONFIGURATION, node_IID1, node1, true);
  17.        
  18.         try {
  19.             tx1.submit().checkedGet();
  20.         } catch (TransactionCommitFailedException ex) {
  21.             LOG.error("Transaction failed: {}", ex.toString());
  22.             throw new RuntimeException(ex);
  23.         }
  24.  
  25.         LOG.info("*** Writing augmented ofl3 node");
  26.        
  27.         NodeAttributes attr = new TypeFbBuilder()
  28.                                    .setForwardingBoxName("fb0")
  29.                                    .setDatapathId(new BigInteger("1234"))
  30.                                    .setDatapathType("cisco")
  31.                                    .setBridgeName("Switch1")
  32.                                    .build();
  33.         new TypeHostBuilder();
  34.  
  35.         Ofl3Node ofl3Node = new Ofl3NodeBuilder()
  36.                                 .setNodeAttributes(attr)
  37.                                 .build();
  38.        
  39.         NodeKey key3 = new NodeKey(new NodeId("cvok3"));
  40.         Node node3 = new NodeBuilder()
  41.                     .setKey(key3)
  42.                     .addAugmentation(Ofl3Node.class, ofl3Node)
  43.                     .build();
  44.        
  45.         WriteTransaction tx3 = dataBroker.newWriteOnlyTransaction();
  46.         InstanceIdentifier<Node> node_IID3 = NETWORK_IID.child(Node.class, key3);
  47.         tx3.put(LogicalDatastoreType.CONFIGURATION, node_IID3, node3, true);
  48.        
  49.         try {
  50.             tx3.submit().checkedGet();
  51.         } catch (TransactionCommitFailedException ex) {
  52.             LOG.error("Transaction failed: {}", ex.toString());
  53.             throw new RuntimeException(ex);
  54.         }
  55.  
  56.         LOG.info("*** Writing node with TP");
  57.        
  58.         List<TerminationPoint> tpList = new ArrayList<TerminationPoint>();
  59.         TpId tpId = new TpId("tp1");
  60.         tpList.add(new TerminationPointBuilder()
  61.                           .setKey(new TerminationPointKey(tpId))
  62.                           .setTpId(tpId)
  63.                           .build());
  64.        
  65.         Node1 node1_1 = new Node1Builder()
  66.                             .setTerminationPoint(tpList)
  67.                             .build();
  68.        
  69.         NodeKey key2 = new NodeKey(new NodeId("cvok2"));
  70.         Node node2 = new NodeBuilder()
  71.                      .setKey(key2)
  72.                      .addAugmentation(Node1.class, node1_1)
  73.                      .build();
  74.        
  75.         WriteTransaction tx2 = dataBroker.newWriteOnlyTransaction();
  76.         InstanceIdentifier<Node> node_IID2 = NETWORK_IID.child(Node.class, key2);
  77.         tx2.put(LogicalDatastoreType.CONFIGURATION, node_IID2, node2, true);
  78.        
  79.         try {
  80.             tx2.submit().checkedGet();
  81.         } catch (TransactionCommitFailedException ex) {
  82.             LOG.error("Transaction failed: {}", ex.toString());
  83.             throw new RuntimeException(ex);
  84.         }
  85.        
  86.         LOG.info("*** Adding another tp to node with existing tp");
  87.  
  88.         List<TerminationPoint> tpList2 = new ArrayList<TerminationPoint>();
  89.         TpId tpId2 = new TpId("tp2");
  90.         tpList2.add(new TerminationPointBuilder()
  91.                           .setKey(new TerminationPointKey(tpId2))
  92.                           .setTpId(tpId2)
  93.                           .build());
  94.        
  95.         Node1 node1_2 = new Node1Builder()
  96.                             .setTerminationPoint(tpList2)
  97.                             .build();
  98.        
  99.         NodeKey key4 = new NodeKey(new NodeId("cvok2"));
  100.         Node node4 = new NodeBuilder()
  101.                      .setKey(key4)
  102.                      .addAugmentation(Node1.class, node1_2)
  103.                      .build();
  104.        
  105.         WriteTransaction tx4 = dataBroker.newWriteOnlyTransaction();
  106.         InstanceIdentifier<Node> node_IID4 = NETWORK_IID.child(Node.class, key4);
  107.         tx4.merge(LogicalDatastoreType.CONFIGURATION, node_IID4, node4, true);
  108.        
  109.         try {
  110.             tx4.submit().checkedGet();
  111.         } catch (TransactionCommitFailedException ex) {
  112.             LOG.error("Transaction failed: {}", ex.toString());
  113.             throw new RuntimeException(ex);
  114.         }
  115.  
  116.         LOG.info("*** Adding yet another tp to node with two existing tp's");
  117.         NodeKey key5 = new NodeKey(new NodeId("cvok2"));
  118.         TpId tpId5 = new TpId("tp3");
  119.         TerminationPointKey tpKey5 = new TerminationPointKey(tpId5);
  120.         TerminationPoint tp = new TerminationPointBuilder()
  121.                                         .setKey(new TerminationPointKey(tpId5))
  122.                                         .setTpId(tpId5)
  123.                                         .build();
  124.      
  125.         WriteTransaction tx5 = dataBroker.newWriteOnlyTransaction();
  126.         KeyedInstanceIdentifier<TerminationPoint, TerminationPointKey> tp_IID1 = NETWORK_IID
  127.                                              .child(Node.class, key5)
  128.                                              .augmentation(Node1.class)
  129.                                              .child(TerminationPoint.class, tpKey5);
  130.         tx5.put(LogicalDatastoreType.CONFIGURATION, tp_IID1, tp, true);
  131.        
  132.         try {
  133.             tx5.submit().checkedGet();
  134.         } catch (TransactionCommitFailedException ex) {
  135.             LOG.error("Transaction failed: {}", ex.toString());
  136.             throw new RuntimeException(ex);
  137.         }
  138.        
  139.         LOG.info("*** Adding a link");
  140.        
  141.         LinkId linkId = new LinkId("Link1");
  142.         LinkKey linkKey = new LinkKey(new LinkId("Link1"));
  143.        
  144.         Link link = new LinkBuilder()
  145.                             .setKey(linkKey)
  146.                             .setLinkId(linkId)
  147.                             .setSource(new SourceBuilder()
  148.                                             .setSourceNode(new NodeId("node1"))
  149.                                             .setSourceTp("tp1")
  150.                                             .build())
  151.                             .setDestination(new DestinationBuilder()
  152.                                             .setDestNode(new NodeId("node2"))
  153.                                             .setDestTp("tp2")
  154.                                             .build())
  155.                             .build();
  156.        
  157.         KeyedInstanceIdentifier<Link, LinkKey> link_IID = NETWORK_IID
  158.                 .augmentation(Network1.class)
  159.                 .child(Link.class, linkKey);
  160.  
  161.         WriteTransaction tx6 = dataBroker.newWriteOnlyTransaction();        
  162.         tx6.put(LogicalDatastoreType.CONFIGURATION, link_IID, link, true);
  163.        
  164.         try {
  165.             tx6.submit().checkedGet();
  166.         } catch (TransactionCommitFailedException ex) {
  167.             LOG.error("Transaction failed: {}", ex.toString());
  168.             throw new RuntimeException(ex);
  169.         }
  170.  
  171.         LOG.info("*** Done");
  172.    }
Add Comment
Please, Sign In to add comment