Ask is moving to Stack Overflow and Serverfault.com! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode

0

How do I put a Node/Link into Datastore?

asked 2016-08-12 06:38:16 -0700

Gamuto gravatar image

updated 2017-01-05 03:41:27 -0700

Hey folks,

I'm currently working on some code to create a Topology and put it into the operational Datastore, so ODL thinks there is a Topology existent (it's for testing purposes).

So far I know, that in order to put something into the operational datastore, I have to do the following steps:

  • Get a DataBroker

  • Create a WriteTransaction

  • Create an InstanceIdentifier

  • Put my transaction into the operational datastore

My code for putting a simple node into the default topology "flow:1" looks like this so far:

private void createSampleTopology(DataBroker db) {
//Create a WriteTransaction
WriteTransaction transaction = db.newWriteOnlyTransaction();

//Create an InstanceIdentifier
InstanceIdentifier<Node> nodeIID = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(new TopologyId("flow:1"))).child(Node.class);

//Create a Node
Node switch1 = new  NodeBuilder().setNodeId(new NodeId("openflow:1").build();

//Put my transaction into the operational datastore
transaction.put(LogicalDatastoreType.OPERATIONAL, nodeIID, switch1);
}

However, my code does not work and throws errors upon loaded into ODL.

It seems like I didn't fully understand the concept of putting data into the datastore by using transactions, yet. My first guess would be a wrong InstanceIdentifier.

Can you guys help me out?

Thanks a lot in advance!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-08-12 08:42:18 -0700

Gamuto gravatar image

Alright, I already figured out a way that works. For everyone interested, here's the code I'm using.

private void createSampleTopology(DataBroker db) {
        //Create a WriteTransaction
        WriteTransaction transaction = db.newWriteOnlyTransaction();
        //Create an InstanceIdentifier pointing at the default topology "flow:1", 
        //which is created upon start of ODL
        InstanceIdentifier<Topology> topoIID = InstanceIdentifier.create(NetworkTopology.class)
                .child(Topology.class, new TopologyKey(new TopologyId("flow:1")));

        //Creating a new Node and a NodeList to put the node in
        Node switch1 = new NodeBuilder()
                .setKey(new NodeKey(new NodeId("openflow:1")))
                .build();
        List<Node> nodeList = new ArrayList<Node>();
        nodeList.add(switch1);

        //Creating a new topology with the same TopologyKey as the default one already existing
        //and adding the NodeList upon building
        Topology topo = new TopologyBuilder()
                .setKey(new TopologyKey(new TopologyId("flow:1")))
                .setNode(nodeList)
                .build();

        //merging (instead of putting) my own topology 
        //with the changes I want into the already existing one
        transaction.merge(LogicalDatastoreType.OPERATIONAL, path, topo);
        //submitting my transaction (forgot about that before)
        transaction.submit();   
    }

Be aware that there is a lot more information you can set on building of a Node such as TerminationPoints and such.

I'm also not sure if this is the most efficient way of putting a new node/link/topology into the operational datastore. If you're aware of a different approach, please feel free to post it in this thread.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2016-08-12 06:38:16 -0700

Seen: 67 times

Last updated: Jan 05