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.EvcUtils;
18 import org.opendaylight.unimgr.utils.MdsalUtils;
19 import org.opendaylight.unimgr.utils.OvsdbUtils;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
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.Link;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.common.base.Optional;
30 public class EvcAddCommand extends AbstractCommand<Link> {
32 private static final Logger LOG = LoggerFactory.getLogger(EvcAddCommand.class);
34 public EvcAddCommand(final DataBroker dataBroker, final DataTreeModification<Link> newEvcLink) {
35 super(dataBroker, newEvcLink);
39 public void execute() {
40 final InstanceIdentifier<?> evcKey = dataObject.getRootPath().getRootIdentifier();
41 Optional<Link> optLinks = MdsalUtils.readLink(dataBroker, LogicalDatastoreType.OPERATIONAL, evcKey);
42 if (!optLinks.isPresent()) {
43 final Link evcLink = dataObject.getRootNode().getDataAfter();
44 final EvcAugmentation evc = evcLink.getAugmentation(EvcAugmentation.class);
46 // For now, we assume that there is 1 uni per source/destination
47 if ((evc.getUniDest() == null) || evc.getUniDest().isEmpty()) {
48 LOG.error("Destination UNI cannot be null.");
51 if ((evc.getUniSource() == null) || evc.getUniSource().isEmpty()) {
52 LOG.error("Source UNI cannot be null.");
55 LOG.info("New EVC created, source IP: {} destination IP {}.",
56 evc.getUniSource().iterator().next().getIpAddress().getIpv4Address(),
57 evc.getUniDest().iterator().next().getIpAddress().getIpv4Address());
58 InstanceIdentifier<Node> sourceUniIid;
59 InstanceIdentifier<Node> destinationUniIid;
60 //FIXME we are assuming that there is only 1 UNI source and destination
62 final InstanceIdentifier<?> iidSource = evc.getUniSource().iterator().next().getUni();
63 if (iidSource != null) {
64 sourceUniIid = iidSource.firstIdentifierOf(Node.class);
66 sourceUniIid = UnimgrMapper.getUniIid(dataBroker,
67 evc.getUniSource().iterator().next().getIpAddress(),
68 LogicalDatastoreType.OPERATIONAL);
70 final InstanceIdentifier<?> iidDest = evc.getUniDest().iterator().next().getUni();
71 if (iidDest != null) {
72 destinationUniIid = iidDest.firstIdentifierOf(Node.class);
74 destinationUniIid = UnimgrMapper.getUniIid(dataBroker,
75 evc.getUniDest().iterator().next().getIpAddress(),
76 LogicalDatastoreType.OPERATIONAL);
78 final Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
79 LogicalDatastoreType.OPERATIONAL,
81 final Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
82 LogicalDatastoreType.OPERATIONAL,
86 // Retrieve the source and destination Unis
87 if (optionalUniSource.isPresent() && optionalUniDestination.isPresent()) {
88 uniSource = optionalUniSource.get();
89 uniDestination = optionalUniDestination.get();
90 // Set source and destination
91 final UniAugmentation sourceUniAugmentation =
92 uniSource.getAugmentation(UniAugmentation.class);
93 final UniAugmentation destinationUniAugmentation =
94 uniDestination.getAugmentation(UniAugmentation.class);
95 final Optional<Node> optionalSourceOvsdbNode =
96 MdsalUtils.readNode(dataBroker,
97 LogicalDatastoreType.OPERATIONAL,
101 final Optional<Node> optionalDestinationOvsdbNode =
102 MdsalUtils.readNode(dataBroker,
103 LogicalDatastoreType.OPERATIONAL,
104 destinationUniAugmentation
107 if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
108 final InstanceIdentifier<Node> sourceBridgeIid =
109 UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
110 final Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
111 LogicalDatastoreType.OPERATIONAL,
113 final InstanceIdentifier<Node> destinationBridgeIid =
114 UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
115 final Optional<Node> optionalDestinationBr = MdsalUtils.readNode(dataBroker,
116 LogicalDatastoreType.OPERATIONAL,
117 destinationBridgeIid);
118 //update ovsdb qos-entry and queues with max-rate to match evc ingress BW
119 OvsdbUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
122 if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
123 sourceBr = optionalSourceBr.get();
124 destinationBr = optionalDestinationBr.get();
125 OvsdbUtils.createTerminationPointNode(dataBroker,
126 uniSource.getAugmentation(UniAugmentation.class),
128 UnimgrConstants.DEFAULT_BRIDGE_NAME,
129 UnimgrConstants.DEFAULT_TUNNEL_IFACE);
130 OvsdbUtils.createGreTunnel(dataBroker,
131 uniSource.getAugmentation(UniAugmentation.class),
132 uniDestination.getAugmentation(UniAugmentation.class),
134 UnimgrConstants.DEFAULT_BRIDGE_NAME,
135 UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
136 OvsdbUtils.createTerminationPointNode(dataBroker,
137 uniDestination.getAugmentation(UniAugmentation.class),
139 UnimgrConstants.DEFAULT_BRIDGE_NAME,
140 UnimgrConstants.DEFAULT_TUNNEL_IFACE);
141 OvsdbUtils.createGreTunnel(dataBroker,
142 uniDestination.getAugmentation(UniAugmentation.class),
143 uniSource.getAugmentation(UniAugmentation.class), destinationBr,
144 UnimgrConstants.DEFAULT_BRIDGE_NAME,
145 UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
146 EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
152 EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
159 LOG.info("Unable to retrieve the source and/or destination bridge.");
162 LOG.info("Uname to retrieve the source and/or destination ovsdbNode.");
165 LOG.info("Unable to retrieve the source and/or destination Uni.");