2 * Copyright (c) 2014 Cisco 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;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.ovsdb.lib.notation.Mutator;
16 import org.opendaylight.ovsdb.lib.notation.UUID;
17 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
18 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
19 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
20 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
21 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
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.collect.Sets;
30 public class BridgeCreateCommand implements TransactCommand {
31 private AsyncDataChangeEvent<InstanceIdentifier<?>, OvsdbBridgeAugmentation> changes;
32 private static final Logger LOG = LoggerFactory.getLogger(BridgeCreateCommand.class);
35 public BridgeCreateCommand(AsyncDataChangeEvent<InstanceIdentifier<?>, OvsdbBridgeAugmentation> changes) {
36 this.changes = changes;
40 public void execute(TransactionBuilder transaction) {
41 Map<InstanceIdentifier<Node>, OvsdbBridgeAugmentation> created = TransactUtils.extractOvsdbManagedNodeCreate(changes);
42 for(OvsdbBridgeAugmentation ovsdbManagedNode: created.values()) {
43 LOG.debug("Received request to create ovsdb bridge name: {} uuid: {}",
44 ovsdbManagedNode.getBridgeName(),
45 ovsdbManagedNode.getBridgeUuid());
47 Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class);
48 bridge.setName(ovsdbManagedNode.getBridgeName().getValue());
49 String namedUuid = "Bridge_" + ovsdbManagedNode.getBridgeName().getValue();
50 bridge.setName(ovsdbManagedNode.getBridgeName().getValue());
51 if(SouthboundMapper.createOvsdbBridgeProtocols(ovsdbManagedNode) != null
52 && SouthboundMapper.createOvsdbBridgeProtocols(ovsdbManagedNode).size() > 0){
53 bridge.setProtocols(SouthboundMapper.createOvsdbBridgeProtocols(ovsdbManagedNode));
55 transaction.add(op.insert(bridge).withId(namedUuid));
58 OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class);
59 ovs.setBridges(Sets.newHashSet(new UUID(namedUuid)));
60 transaction.add(op.mutate(ovs).addMutation(ovs.getBridgesColumn().getSchema(),
62 ovs.getBridgesColumn().getData())