2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.openflow.samples.consumer;
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;
33 public class SimpleDropFirewall {
35 private ConsumerContext context;
36 private SalFlowService flowService;
37 private DataTreeChangeListener listener = new NodeListener();
38 private DataBrokerService data;
40 public void setContext(ConsumerContext session) {
41 this.context = session;
44 public void setFlowService(SalFlowService flowService) {
45 this.flowService = flowService;
49 NotificationService notificationService = context.getSALService(NotificationService.class);
52 public boolean addFlow(AddFlowInput flow) throws InterruptedException,
53 ExecutionException, TimeoutException {
54 Future<RpcResult<AddFlowOutput>> result = flowService.addFlow(flow);
56 return result.get(5, TimeUnit.SECONDS).isSuccessful();
59 private class NodeListener implements DataTreeChangeListener<Node> {
61 public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> modifications) {
62 for (DataTreeModification modification : modifications) {
63 if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) {
71 private class InventoryListener implements OpendaylightInventoryListener {
74 public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
75 // TODO Auto-generated method stub
80 public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
85 public void onNodeRemoved(NodeRemoved notification) {
86 // TODO Auto-generated method stub
91 public void onNodeUpdated(NodeUpdated notification) {
92 // TODO Auto-generated method stub