/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
import org.opendaylight.ovsdb.lib.notation.Mutator;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.Mutate;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
import org.opendaylight.ovsdb.southbound.SouthboundProvider;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.CheckedFuture;
getOperationalState().getBridgeTerminationPoint(terminationPointIid);
if (!terminationPointOptional.isPresent()) {
// Configure interface
- String interfaceUuid = "Interface_" + SouthboundMapper.getRandomUUID();;
+ String interfaceUuid = "Interface_" + SouthboundMapper.getRandomUUID();
Interface ovsInterface =
TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Interface.class);
createInterface(terminationPoint, ovsInterface);
createInterfaceOptions(terminationPoint, ovsInterface);
createInterfaceOtherConfig(terminationPoint, ovsInterface);
createInterfaceExternalIds(terminationPoint, ovsInterface);
+ createInterfaceLldp(terminationPoint, ovsInterface);
}
private void createInterfaceType(final OvsdbTerminationPointAugmentation terminationPoint,
//Configure optional input
if (terminationPoint.getOptions() != null) {
- HashMap<String, String> optionsMap = new HashMap<String, String>();
- for (Options option : terminationPoint.getOptions()) {
- optionsMap.put(option.getOption(), option.getValue());
- }
try {
- ovsInterface.setOptions(ImmutableMap.copyOf(optionsMap));
+ ovsInterface.setOptions(YangUtils.convertYangKeyValueListToMap(terminationPoint.getOptions(),
+ Options::getOption, Options::getValue));
} catch (NullPointerException e) {
- LOG.warn("Incomplete OVSDB interface options");
+ LOG.warn("Incomplete OVSDB interface options", e);
}
}
}
List<InterfaceExternalIds> interfaceExternalIds =
terminationPoint.getInterfaceExternalIds();
if (interfaceExternalIds != null && !interfaceExternalIds.isEmpty()) {
- HashMap<String, String> externalIdsMap = new HashMap<String, String>();
- for (InterfaceExternalIds externalId: interfaceExternalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
try {
- ovsInterface.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ ovsInterface.setExternalIds(YangUtils.convertYangKeyValueListToMap(interfaceExternalIds,
+ InterfaceExternalIds::getExternalIdKey, InterfaceExternalIds::getExternalIdValue));
} catch (NullPointerException e) {
- LOG.warn("Incomplete OVSDB interface external_ids");
+ LOG.warn("Incomplete OVSDB interface external_ids", e);
}
}
}
List<InterfaceOtherConfigs> interfaceOtherConfigs =
terminationPoint.getInterfaceOtherConfigs();
if (interfaceOtherConfigs != null && !interfaceOtherConfigs.isEmpty()) {
- HashMap<String, String> otherConfigsMap = new HashMap<String, String>();
+ Map<String, String> otherConfigsMap = new HashMap<>();
for (InterfaceOtherConfigs interfaceOtherConfig : interfaceOtherConfigs) {
otherConfigsMap.put(interfaceOtherConfig.getOtherConfigKey(),
interfaceOtherConfig.getOtherConfigValue());
}
}
+ private void createInterfaceLldp(
+ final OvsdbTerminationPointAugmentation terminationPoint,
+ final Interface ovsInterface) {
+
+ try {
+ List<InterfaceLldp> interfaceLldpList =
+ terminationPoint.getInterfaceLldp();
+ if (interfaceLldpList != null && !interfaceLldpList.isEmpty()) {
+ try {
+ ovsInterface.setLldp(YangUtils.convertYangKeyValueListToMap(interfaceLldpList,
+ InterfaceLldp::getLldpKey, InterfaceLldp::getLldpValue));
+ } catch (NullPointerException e) {
+ LOG.warn("Incomplete OVSDB interface lldp", e);
+ }
+ }
+ } catch (SchemaVersionMismatchException e) {
+ LOG.debug("lldp column for Interface Table unsupported for this version of ovsdb schema", e);
+ }
+ }
+
private void createPortExternalIds(
final OvsdbTerminationPointAugmentation terminationPoint,
final Port port) {
List<PortExternalIds> portExternalIds = terminationPoint.getPortExternalIds();
if (portExternalIds != null && !portExternalIds.isEmpty()) {
- HashMap<String, String> externalIdsMap = new HashMap<String, String>();
- for (PortExternalIds externalId: portExternalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
try {
- port.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ port.setExternalIds(YangUtils.convertYangKeyValueListToMap(portExternalIds,
+ PortExternalIds::getExternalIdKey, PortExternalIds::getExternalIdValue));
} catch (NullPointerException e) {
- LOG.warn("Incomplete OVSDB port external_ids");
+ LOG.warn("Incomplete OVSDB port external_ids", e);
}
}
}
final Port port) {
if (terminationPoint.getVlanTag() != null) {
- Set<Long> vlanTag = new HashSet<Long>();
+ Set<Long> vlanTag = new HashSet<>();
vlanTag.add(terminationPoint.getVlanTag().getValue().longValue());
port.setTag(vlanTag);
}
final Port port) {
if (terminationPoint.getTrunks() != null && terminationPoint.getTrunks().size() > 0) {
- Set<Long> portTrunks = new HashSet<Long>();
+ Set<Long> portTrunks = new HashSet<>();
List<Trunks> modelTrunks = terminationPoint.getTrunks();
for (Trunks trunk: modelTrunks) {
if (trunk.getTrunk() != null) {
final OvsdbTerminationPointAugmentation terminationPoint,
final Port port) {
if (terminationPoint.getVlanMode() != null) {
- Set<String> portVlanMode = new HashSet<String>();
+ Set<String> portVlanMode = new HashSet<>();
VlanMode modelVlanMode = terminationPoint.getVlanMode();
portVlanMode.add(SouthboundConstants.VLANMODES.values()[modelVlanMode.getIntValue() - 1].getMode());
port.setVlanMode(portVlanMode);
List<PortOtherConfigs> portOtherConfigs =
terminationPoint.getPortOtherConfigs();
if (portOtherConfigs != null && !portOtherConfigs.isEmpty()) {
- HashMap<String, String> otherConfigsMap = new HashMap<String, String>();
- for (PortOtherConfigs portOtherConfig : portOtherConfigs) {
- otherConfigsMap.put(portOtherConfig.getOtherConfigKey(),
- portOtherConfig.getOtherConfigValue());
- }
try {
- ovsPort.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
+ ovsPort.setOtherConfig(YangUtils.convertYangKeyValueListToMap(portOtherConfigs,
+ PortOtherConfigs::getOtherConfigKey, PortOtherConfigs::getOtherConfigValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB port other_config", e);
}
public static void stampInstanceIdentifier(TransactionBuilder transaction,InstanceIdentifier<TerminationPoint> iid,
String interfaceName) {
Port port = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Port.class);
- port.setName(interfaceName);;
+ port.setName(interfaceName);
port.setExternalIds(Collections.<String,String>emptyMap());
Mutate mutate = TransactUtils.stampInstanceIdentifierMutation(transaction,
iid,