2 * Copyright (c) 2015 Brocade Communications 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
8 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
10 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
12 import java.util.HashSet;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
16 import org.opendaylight.ovsdb.lib.notation.Mutator;
17 import org.opendaylight.ovsdb.lib.notation.UUID;
18 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
19 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
20 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
21 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
22 import org.opendaylight.ovsdb.schema.openvswitch.Port;
23 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import com.google.common.collect.ImmutableMap;
32 import com.google.common.collect.Sets;
34 public class TerminationPointCreateCommand implements TransactCommand {
35 private AsyncDataChangeEvent<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> changes;
36 private static final Logger LOG = LoggerFactory.getLogger(TerminationPointCreateCommand.class);
38 public TerminationPointCreateCommand(AsyncDataChangeEvent<InstanceIdentifier<?>,
39 OvsdbTerminationPointAugmentation> changes) {
40 this.changes = changes;
44 public void execute(TransactionBuilder transaction) {
45 for (OvsdbTerminationPointAugmentation terminationPoint: changes.getCreatedData().values()) {
46 LOG.debug("Received request to create termination point {} at managed node {}",
47 terminationPoint.getName(),
48 terminationPoint.getAttachedTo().getValue().firstIdentifierOf(Node.class));
51 // Configure interface
52 String interfaceUuid = "Interface_" + terminationPoint.getName();
53 Interface ovsInterface = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Interface.class);
54 ovsInterface.setName(terminationPoint.getName());
55 ovsInterface.setType(SouthboundMapper.createOvsdbInterfaceType(terminationPoint.getInterfaceType()));
56 Integer ofPort = terminationPoint.getOfport();
58 ovsInterface.setOpenFlowPort(Sets.newHashSet(ofPort));
60 Integer ofPortRequest = terminationPoint.getOfportRequest();
61 if (ofPortRequest != null) {
62 ovsInterface.setOpenFlowPortRequest(Sets.newHashSet(ofPortRequest));
65 //Configure optional input
66 if (terminationPoint.getOptions() != null) {
67 for (Options option : terminationPoint.getOptions()) {
68 ovsInterface.setOptions(ImmutableMap.of(option.getOption(),option.getValue()));
71 transaction.add(op.insert(ovsInterface).withId(interfaceUuid));
73 // Configure port with the above interface details
74 String portUuid = "Port_" + terminationPoint.getName();
75 Port port = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Port.class);
76 port.setName(terminationPoint.getName());
77 port.setInterfaces(Sets.newHashSet(new UUID(interfaceUuid)));
78 if (terminationPoint.getVlanTag() != null) {
79 Set<Long> vlanTag = new HashSet<Long>();
80 vlanTag.add(terminationPoint.getVlanTag().getValue().longValue());
83 transaction.add(op.insert(port).withId(portUuid));
85 //Configure bridge with the above port details
86 Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class);
87 bridge.setName(terminationPoint.getBridgeName());
88 bridge.setPorts(Sets.newHashSet(new UUID(portUuid)));
90 transaction.add(op.mutate(bridge)
91 .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT,bridge.getPortsColumn().getData())
92 .where(bridge.getNameColumn().getSchema().opEqual(bridge.getNameColumn().getData())).build());