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.command;
11 import java.util.Map.Entry;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.unimgr.impl.UnimgrConstants;
16 import org.opendaylight.unimgr.impl.UnimgrMapper;
17 import org.opendaylight.unimgr.impl.UnimgrUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Optional;
28 public class EvcCreateCommand extends AbstractCreateCommand {
30 private static final Logger LOG = LoggerFactory.getLogger(EvcCreateCommand.class);
32 public EvcCreateCommand(DataBroker dataBroker,
33 Map<InstanceIdentifier<?>, DataObject> changes) {
34 super.dataBroker = dataBroker;
35 super.changes = changes;
39 public void execute() {
40 for (Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
41 if (created.getValue() != null && created.getValue() instanceof EvcAugmentation) {
42 EvcAugmentation evc = (EvcAugmentation) created.getValue();
43 InstanceIdentifier<?> evcKey = created.getKey();
44 LOG.trace("New EVC created, source IP: {} destination IP {}.",
45 evc.getUniSource().iterator().next().getIpAddress().getIpv4Address(),
46 evc.getUniDest().iterator().next().getIpAddress().getIpv4Address());
47 // For now, we assume that there is 1 uni per source/destination
48 if (evc.getUniDest() == null || evc.getUniDest().isEmpty()) {
49 LOG.error("Destination UNI cannot be null.");
52 if (evc.getUniSource() == null || evc.getUniSource().isEmpty()) {
53 LOG.error("Source UNI cannot be null.");
56 InstanceIdentifier<Node> sourceUniIid;
57 InstanceIdentifier<Node> destinationUniIid;
58 if (evc.getUniSource().iterator().next().getUni() != null) {
59 sourceUniIid = evc.getUniSource().iterator().next().getUni().firstIdentifierOf(Node.class);
61 sourceUniIid = UnimgrMapper.getUniIid(dataBroker,
62 evc.getUniSource().iterator().next().getIpAddress(),
63 LogicalDatastoreType.OPERATIONAL);
65 if (evc.getUniDest().iterator().next().getUni() != null) {
66 destinationUniIid = evc.getUniDest().iterator().next().getUni().firstIdentifierOf(Node.class);
68 destinationUniIid = UnimgrMapper.getUniIid(dataBroker,
69 evc.getUniDest().iterator().next().getIpAddress(),
70 LogicalDatastoreType.OPERATIONAL);
72 Optional<Node> optionalUniSource = UnimgrUtils.readNode(dataBroker,
73 LogicalDatastoreType.OPERATIONAL,
75 Optional<Node> optionalUniDestination = UnimgrUtils.readNode(dataBroker,
76 LogicalDatastoreType.OPERATIONAL,
80 // Retrieve the source and destination Unis
81 if (optionalUniSource.isPresent() && optionalUniDestination.isPresent()) {
82 uniSource = optionalUniSource.get();
83 uniDestination = optionalUniDestination.get();
84 // Set source and destination
85 UniAugmentation sourceUniAugmentation =
86 uniSource.getAugmentation(UniAugmentation.class);
87 UniAugmentation destinationUniAugmentation =
88 uniDestination.getAugmentation(UniAugmentation.class);
89 Optional<Node> optionalSourceOvsdbNode =
90 UnimgrUtils.readNode(dataBroker,
91 LogicalDatastoreType.OPERATIONAL,
95 Optional<Node> optionalDestinationOvsdbNode =
96 UnimgrUtils.readNode(dataBroker,
97 LogicalDatastoreType.OPERATIONAL,
98 destinationUniAugmentation
101 if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
102 InstanceIdentifier<Node> sourceBridgeIid =
103 UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
104 Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
105 LogicalDatastoreType.OPERATIONAL,
107 InstanceIdentifier<Node> destinationBridgeIid =
108 UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
109 Optional<Node> optionalDestinationBr = UnimgrUtils.readNode(dataBroker,
110 LogicalDatastoreType.OPERATIONAL,
111 destinationBridgeIid);
114 if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
115 sourceBr = optionalSourceBr.get();
116 destinationBr = optionalDestinationBr.get();
117 UnimgrUtils.createTerminationPointNode(dataBroker,
118 uniSource.getAugmentation(UniAugmentation.class),
120 UnimgrConstants.DEFAULT_BRIDGE_NAME,
121 UnimgrConstants.DEFAULT_TUNNEL_IFACE,
122 UnimgrConstants.DEFAULT_GRE_NAME);
123 UnimgrUtils.createGreTunnel(dataBroker,
124 uniSource.getAugmentation(UniAugmentation.class),
125 uniDestination.getAugmentation(UniAugmentation.class),
127 UnimgrConstants.DEFAULT_BRIDGE_NAME,
129 UnimgrUtils.createTerminationPointNode(dataBroker,
130 uniSource.getAugmentation(UniAugmentation.class),
132 UnimgrConstants.DEFAULT_BRIDGE_NAME,
133 UnimgrConstants.DEFAULT_TUNNEL_IFACE,
134 UnimgrConstants.DEFAULT_GRE_NAME);
135 UnimgrUtils.createGreTunnel(dataBroker,
136 uniDestination.getAugmentation(UniAugmentation.class),
137 uniSource.getAugmentation(UniAugmentation.class), destinationBr,
138 UnimgrConstants.DEFAULT_BRIDGE_NAME,
140 UnimgrUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
146 UnimgrUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
153 LOG.info("Unable to retrieve the source and/or destination bridge.");
156 LOG.info("Uname to retrieve the source and/or destination ovsdbNode.");
159 LOG.info("Unable to retrieve the source and/or destination Uni.");