ID's are made in sync with openflow specification. Flow/Group/Table/Port/Queue/Meter...
[controller.git] / opendaylight / md-sal / compatibility / flow-management-compatibility / src / main / java / org / opendaylight / controller / md / frm / compatibility / SampleConsumer.java
1 package org.opendaylight.controller.md.frm.compatibility;
2
3 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
4 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
5 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowBuilder;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
12
13 public class SampleConsumer {
14
15     ConsumerContext context;
16
17     void addFlowExample() {
18
19         DataBrokerService dataService = context.getSALService(DataBrokerService.class);
20
21         DataModificationTransaction transaction = dataService.beginTransaction();
22         Flow flow = createSampleFlow("foo", null);
23         InstanceIdentifier<Flow> path = InstanceIdentifier.builder().node(Flows.class).node(Flow.class, flow.getKey())
24                 .toInstance();
25         transaction.putConfigurationData(path, flow);
26
27         transaction.commit();
28
29         dataService.readConfigurationData(path);
30     }
31
32     Flow createSampleFlow(String name, NodeRef node) {
33         FlowBuilder ret = new FlowBuilder();
34         FlowKey key = new FlowKey(Long.parseLong(name), node);
35         ret.setKey(key);
36         return ret.build();
37     }
38 }