2 * Copyright (c) 2016 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
9 package org.opendaylight.unimgr.command;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.unimgr.api.AbstractCommand;
15 import org.opendaylight.unimgr.impl.UnimgrConstants;
16 import org.opendaylight.unimgr.impl.UnimgrMapper;
17 import org.opendaylight.unimgr.utils.MdsalUtils;
18 import org.opendaylight.unimgr.utils.OvsdbUtils;
19 import org.opendaylight.unimgr.utils.UniUtils;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.common.base.Optional;
29 public class UniAddCommand extends AbstractCommand<Node>{
31 private static final Logger LOG = LoggerFactory.getLogger(UniAddCommand.class);
33 public UniAddCommand(final DataBroker dataBroker, final DataTreeModification<Node> newUniNode) {
34 super(dataBroker, newUniNode);
38 public void execute() {
39 final InstanceIdentifier<?> uniKey = dataObject.getRootPath().getRootIdentifier();
40 final Optional<Node> optNode = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, uniKey);
41 if(!optNode.isPresent()) {
42 final Node uniNode = dataObject.getRootNode().getDataAfter();
43 final UniAugmentation uni = uniNode.getAugmentation(UniAugmentation.class);
45 LOG.info("New UNI created {}.", uni.getIpAddress().getIpv4Address());
46 // We assume the ovs is in active mode tcp:ipAddress:6640
47 if (uni.getOvsdbNodeRef() != null) {
48 final OvsdbNodeRef ovsdbNodeRef = uni.getOvsdbNodeRef();
49 final Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
50 LogicalDatastoreType.OPERATIONAL,
51 ovsdbNodeRef.getValue());
52 if (!optionalNode.isPresent()) {
53 LOG.info("Invalid OVSDB node instance identifier specified, "
54 + "attempting to retrieve the node.");
55 final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
58 if (optionalOvsdbNode.isPresent()) {
59 ovsdbNode = optionalOvsdbNode.get();
60 LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
61 // Update QoS entries to ovsdb if speed is configured to UNI node
62 if (uni.getSpeed() != null) {
63 OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
65 UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
71 ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
73 LOG.info("Could not retrieve the OVSDB node,"
74 + " created a new one: {}", ovsdbNode.getNodeId());
75 UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
83 // We assume the ovs is in passive mode
84 // Check if the ovsdb node exist
85 final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
88 if (optionalOvsdbNode.isPresent()) {
89 ovsdbNode = optionalOvsdbNode.get();
90 final InstanceIdentifier<Node> ovsdbIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId());
91 LOG.info("Retrieved the OVSDB node");
92 // Update QoS entries to ovsdb if speed is configured to UNI node
93 if (uni.getSpeed() != null) {
94 OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
96 OvsdbUtils.createBridgeNode(dataBroker,
99 UnimgrConstants.DEFAULT_BRIDGE_NAME);
100 UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
105 UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNode, dataBroker);
107 ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
109 if (ovsdbNode != null) {
110 LOG.info("Could not retrieve the OVSDB node,"
111 + "created a new one: {}", ovsdbNode.getNodeId());
112 UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,