2 * Copyright (c) 2014, 2015 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
9 package org.opendaylight.openflowplugin.openflow.ofswitch.config;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.openflowplugin.api.OFConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
25 import org.opendaylight.yangtools.concepts.ListenerRegistration;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 * Created by Martin Bobak mbobak@cisco.com on 10/14/14.
32 public class DefaultConfigPusher implements AutoCloseable, DataChangeListener {
34 private final NodeConfigService nodeConfigService;
35 private final DataBroker dataBroker;
36 private ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
38 public DefaultConfigPusher(NodeConfigService nodeConfigService, DataBroker dataBroker) {
39 this.nodeConfigService = nodeConfigService;
40 this.dataBroker = dataBroker;
44 InstanceIdentifier<FlowCapableNode> path = InstanceIdentifier.create(Nodes.class).child(Node.class).
45 augmentation(FlowCapableNode.class);
46 dataChangeListenerRegistration = dataBroker.registerDataChangeListener(
47 LogicalDatastoreType.OPERATIONAL,
48 path, this, AsyncDataBroker.DataChangeScope.BASE);
53 if(dataChangeListenerRegistration != null) {
54 dataChangeListenerRegistration.close();
59 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
60 final Set<InstanceIdentifier<?>> changedDataKeys = change.getCreatedData().keySet();
62 if (changedDataKeys != null) {
63 for (InstanceIdentifier<?> key : changedDataKeys) {
64 SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder();
65 setConfigInputBuilder.setFlag(SwitchConfigFlag.FRAGNORMAL.toString());
66 setConfigInputBuilder.setMissSearchLength(OFConstants.OFPCML_NO_BUFFER);
67 setConfigInputBuilder.setNode(new NodeRef(key.firstIdentifierOf(Node.class)));
68 nodeConfigService.setConfig(setConfigInputBuilder.build());