Convert OF samples to use DTCL instead of DCL
[openflowplugin.git] / samples / sample-consumer / src / main / java / org / opendaylight / openflowplugin / openflow / samples / consumer / SimpleDropFirewall.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.openflow.samples.consumer;
9
10 import java.util.Collection;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.Future;
13 import java.util.concurrent.TimeUnit;
14 import java.util.concurrent.TimeoutException;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
17 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
18 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
20 import org.opendaylight.controller.sal.binding.api.NotificationService;
21 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32
33 public class SimpleDropFirewall {
34
35     private ConsumerContext context;
36     private SalFlowService flowService;
37     private DataTreeChangeListener listener = new NodeListener();
38     private DataBrokerService data;
39
40     public void setContext(ConsumerContext session) {
41         this.context = session;
42     }
43
44     public void setFlowService(SalFlowService flowService) {
45         this.flowService = flowService;
46     }
47
48     public void start() {
49         NotificationService notificationService = context.getSALService(NotificationService.class);
50     }
51
52     public boolean addFlow(AddFlowInput flow) throws InterruptedException,
53             ExecutionException, TimeoutException {
54         Future<RpcResult<AddFlowOutput>> result = flowService.addFlow(flow);
55
56         return result.get(5, TimeUnit.SECONDS).isSuccessful();
57     }
58
59     private class NodeListener implements DataTreeChangeListener<Node> {
60         @Override
61         public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> modifications) {
62             for (DataTreeModification modification : modifications) {
63                 if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) {
64                     // node updated
65                 }
66             }
67         }
68     }
69
70
71     private class InventoryListener implements OpendaylightInventoryListener {
72
73         @Override
74         public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
75             // TODO Auto-generated method stub
76             
77         }
78
79         @Override
80         public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
81             
82         }
83
84         @Override
85         public void onNodeRemoved(NodeRemoved notification) {
86             // TODO Auto-generated method stub
87             
88         }
89
90         @Override
91         public void onNodeUpdated(NodeUpdated notification) {
92             // TODO Auto-generated method stub
93             
94         }
95         
96     }
97 }