Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void topologySetTest(DataBroker dataBroker) {
- final InstanceIdentifier<Network> NETWORK_IID =
- InstanceIdentifier.builder(Network.class, new NetworkKey(new NetworkId("test-network"))).build();
- LOG.info("*** topologySetTest started");
- LOG.info("*** Writing plain node");
- NodeKey key1 = new NodeKey(new NodeId("cvok1"));
- Node node1 = new NodeBuilder()
- .setKey(key1)
- .build();
- WriteTransaction tx1 = dataBroker.newWriteOnlyTransaction();
- InstanceIdentifier<Node> node_IID1 = NETWORK_IID.child(Node.class, key1);
- tx1.put(LogicalDatastoreType.CONFIGURATION, node_IID1, node1, true);
- try {
- tx1.submit().checkedGet();
- } catch (TransactionCommitFailedException ex) {
- LOG.error("Transaction failed: {}", ex.toString());
- throw new RuntimeException(ex);
- }
- LOG.info("*** Writing augmented ofl3 node");
- NodeAttributes attr = new TypeFbBuilder()
- .setForwardingBoxName("fb0")
- .setDatapathId(new BigInteger("1234"))
- .setDatapathType("cisco")
- .setBridgeName("Switch1")
- .build();
- new TypeHostBuilder();
- Ofl3Node ofl3Node = new Ofl3NodeBuilder()
- .setNodeAttributes(attr)
- .build();
- NodeKey key3 = new NodeKey(new NodeId("cvok3"));
- Node node3 = new NodeBuilder()
- .setKey(key3)
- .addAugmentation(Ofl3Node.class, ofl3Node)
- .build();
- WriteTransaction tx3 = dataBroker.newWriteOnlyTransaction();
- InstanceIdentifier<Node> node_IID3 = NETWORK_IID.child(Node.class, key3);
- tx3.put(LogicalDatastoreType.CONFIGURATION, node_IID3, node3, true);
- try {
- tx3.submit().checkedGet();
- } catch (TransactionCommitFailedException ex) {
- LOG.error("Transaction failed: {}", ex.toString());
- throw new RuntimeException(ex);
- }
- LOG.info("*** Writing node with TP");
- List<TerminationPoint> tpList = new ArrayList<TerminationPoint>();
- TpId tpId = new TpId("tp1");
- tpList.add(new TerminationPointBuilder()
- .setKey(new TerminationPointKey(tpId))
- .setTpId(tpId)
- .build());
- Node1 node1_1 = new Node1Builder()
- .setTerminationPoint(tpList)
- .build();
- NodeKey key2 = new NodeKey(new NodeId("cvok2"));
- Node node2 = new NodeBuilder()
- .setKey(key2)
- .addAugmentation(Node1.class, node1_1)
- .build();
- WriteTransaction tx2 = dataBroker.newWriteOnlyTransaction();
- InstanceIdentifier<Node> node_IID2 = NETWORK_IID.child(Node.class, key2);
- tx2.put(LogicalDatastoreType.CONFIGURATION, node_IID2, node2, true);
- try {
- tx2.submit().checkedGet();
- } catch (TransactionCommitFailedException ex) {
- LOG.error("Transaction failed: {}", ex.toString());
- throw new RuntimeException(ex);
- }
- LOG.info("*** Adding another tp to node with existing tp");
- List<TerminationPoint> tpList2 = new ArrayList<TerminationPoint>();
- TpId tpId2 = new TpId("tp2");
- tpList2.add(new TerminationPointBuilder()
- .setKey(new TerminationPointKey(tpId2))
- .setTpId(tpId2)
- .build());
- Node1 node1_2 = new Node1Builder()
- .setTerminationPoint(tpList2)
- .build();
- NodeKey key4 = new NodeKey(new NodeId("cvok2"));
- Node node4 = new NodeBuilder()
- .setKey(key4)
- .addAugmentation(Node1.class, node1_2)
- .build();
- WriteTransaction tx4 = dataBroker.newWriteOnlyTransaction();
- InstanceIdentifier<Node> node_IID4 = NETWORK_IID.child(Node.class, key4);
- tx4.merge(LogicalDatastoreType.CONFIGURATION, node_IID4, node4, true);
- try {
- tx4.submit().checkedGet();
- } catch (TransactionCommitFailedException ex) {
- LOG.error("Transaction failed: {}", ex.toString());
- throw new RuntimeException(ex);
- }
- LOG.info("*** Adding yet another tp to node with two existing tp's");
- NodeKey key5 = new NodeKey(new NodeId("cvok2"));
- TpId tpId5 = new TpId("tp3");
- TerminationPointKey tpKey5 = new TerminationPointKey(tpId5);
- TerminationPoint tp = new TerminationPointBuilder()
- .setKey(new TerminationPointKey(tpId5))
- .setTpId(tpId5)
- .build();
- WriteTransaction tx5 = dataBroker.newWriteOnlyTransaction();
- KeyedInstanceIdentifier<TerminationPoint, TerminationPointKey> tp_IID1 = NETWORK_IID
- .child(Node.class, key5)
- .augmentation(Node1.class)
- .child(TerminationPoint.class, tpKey5);
- tx5.put(LogicalDatastoreType.CONFIGURATION, tp_IID1, tp, true);
- try {
- tx5.submit().checkedGet();
- } catch (TransactionCommitFailedException ex) {
- LOG.error("Transaction failed: {}", ex.toString());
- throw new RuntimeException(ex);
- }
- LOG.info("*** Adding a link");
- LinkId linkId = new LinkId("Link1");
- LinkKey linkKey = new LinkKey(new LinkId("Link1"));
- Link link = new LinkBuilder()
- .setKey(linkKey)
- .setLinkId(linkId)
- .setSource(new SourceBuilder()
- .setSourceNode(new NodeId("node1"))
- .setSourceTp("tp1")
- .build())
- .setDestination(new DestinationBuilder()
- .setDestNode(new NodeId("node2"))
- .setDestTp("tp2")
- .build())
- .build();
- KeyedInstanceIdentifier<Link, LinkKey> link_IID = NETWORK_IID
- .augmentation(Network1.class)
- .child(Link.class, linkKey);
- WriteTransaction tx6 = dataBroker.newWriteOnlyTransaction();
- tx6.put(LogicalDatastoreType.CONFIGURATION, link_IID, link, true);
- try {
- tx6.submit().checkedGet();
- } catch (TransactionCommitFailedException ex) {
- LOG.error("Transaction failed: {}", ex.toString());
- throw new RuntimeException(ex);
- }
- LOG.info("*** Done");
- }
Add Comment
Please, Sign In to add comment