2 * Copyright (c) 2015 CableLabs 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.unimgr.impl;
11 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
19 import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
20 import org.opendaylight.unimgr.command.TransactionInvoker;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Evc;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopologyBuilder;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.FrameworkUtil;
32 import org.osgi.framework.ServiceRegistration;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import com.google.common.base.Optional;
37 import com.google.common.util.concurrent.CheckedFuture;
39 public class UnimgrProvider implements BindingAwareProvider, AutoCloseable, IUnimgrConsoleProvider {
41 private static final Logger LOG = LoggerFactory.getLogger(UnimgrProvider.class);
43 private UnimgrDataChangeListener listener;
44 private TransactionInvoker invoker;
46 private DataBroker dataBroker;
47 private ServiceRegistration<IUnimgrConsoleProvider> unimgrConsoleRegistration;
50 public void onSessionInitiated(ProviderContext session) {
51 LOG.info("UnimgrProvider Session Initiated");
53 dataBroker = session.getSALService(DataBroker.class);
54 invoker = new TransactionInvoker();
56 BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
57 unimgrConsoleRegistration = context.registerService(IUnimgrConsoleProvider.class, this, null);
59 listener = new UnimgrDataChangeListener(dataBroker, invoker);
61 // Initialize operational and default config data in MD-SAL data store
62 initDatastore(LogicalDatastoreType.CONFIGURATION, UnimgrConstants.UNI_TOPOLOGY_ID);
63 initDatastore(LogicalDatastoreType.OPERATIONAL, UnimgrConstants.UNI_TOPOLOGY_ID);
64 initDatastore(LogicalDatastoreType.CONFIGURATION, UnimgrConstants.EVC_TOPOLOGY_ID);
65 initDatastore(LogicalDatastoreType.OPERATIONAL, UnimgrConstants.EVC_TOPOLOGY_ID);
69 public void close() throws Exception {
70 LOG.info("UnimgrProvider Closed");
71 unimgrConsoleRegistration.unregister();
75 protected void initDatastore(final LogicalDatastoreType type, TopologyId topoId) {
76 InstanceIdentifier<Topology> path = InstanceIdentifier
77 .create(NetworkTopology.class)
78 .child(Topology.class, new TopologyKey(topoId));
79 initializeTopology(type);
80 ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
81 CheckedFuture<Optional<Topology>, ReadFailedException> unimgrTp = transaction.read(type, path);
83 if (!unimgrTp.get().isPresent()) {
84 TopologyBuilder tpb = new TopologyBuilder();
85 tpb.setTopologyId(topoId);
86 transaction.put(type, path, tpb.build());
91 } catch (Exception e) {
92 LOG.error("Error initializing unimgr topology", e);
96 private void initializeTopology(LogicalDatastoreType type) {
97 ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
98 InstanceIdentifier<NetworkTopology> path = InstanceIdentifier.create(NetworkTopology.class);
99 CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = transaction.read(type,path);
101 if (!topology.get().isPresent()) {
102 NetworkTopologyBuilder ntb = new NetworkTopologyBuilder();
103 transaction.put(type,path,ntb.build());
104 transaction.submit();
106 transaction.cancel();
108 } catch (Exception e) {
109 LOG.error("Error initializing unimgr topology {}",e);
114 public boolean addUni(Uni uni) {
116 if (uni.getIpAddress() == null || uni.getMacAddress() == null) {
119 // UniAugmentation uniAugmentation = new UniAugmentationBuilder()
120 // .setIpAddress(uni.getIpAddress())
121 // .setMacAddress(uni.getMacAddress())
123 // ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
124 // InstanceIdentifier<Node> path = UnimgrMapper.getUniAugmentationIidByMac(uni.getMacAddress());
129 public boolean removeUni(String uuid) {
130 // TODO Auto-generated method stub
135 public List<Uni> listUnis(boolean isConfigurationDatastore) {
136 // TODO Auto-generated method stub
141 public Uni getUni(String uuid) {
142 // TODO Auto-generated method stub
147 public boolean removeEvc(String uuid) {
148 // TODO Auto-generated method stub
153 public boolean addEvc(Evc evc) {
154 // TODO Auto-generated method stub
159 public Evc getEvc(String uuid) {
160 // TODO Auto-generated method stub