use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings in project netvirt by opendaylight.
the class HwvtepTerminationPointListener method handlePortAdded.
private List<ListenableFuture<Void>> handlePortAdded(TerminationPoint portAdded, NodeId psNodeId) {
Node psNode = HwvtepUtils.getHwVtepNode(broker, LogicalDatastoreType.OPERATIONAL, psNodeId);
if (psNode != null) {
String psName = psNode.getAugmentation(PhysicalSwitchAugmentation.class).getHwvtepNodeName().getValue();
L2GatewayDevice l2GwDevice = l2GatewayCache.get(psName);
if (l2GwDevice != null) {
if (isL2GatewayConfigured(l2GwDevice)) {
List<L2gatewayConnection> l2GwConns = L2GatewayConnectionUtils.getAssociatedL2GwConnections(broker, l2GwDevice.getL2GatewayIds());
String newPortId = portAdded.getTpId().getValue();
NodeId hwvtepNodeId = new NodeId(l2GwDevice.getHwvtepNodeId());
List<VlanBindings> vlanBindings = getVlanBindings(l2GwConns, hwvtepNodeId, psName, newPortId);
return Collections.singletonList(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(hwvtepNodeId, psName, newPortId, vlanBindings));
}
} else {
LOG.error("{} details are not present in L2Gateway Cache", psName);
}
} else {
LOG.error("{} entry not in config datastore", psNodeId);
}
return Collections.emptyList();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings in project netvirt by opendaylight.
the class HwvtepTerminationPointListener method getVlanBindings.
private List<VlanBindings> getVlanBindings(List<L2gatewayConnection> l2GwConns, NodeId hwvtepNodeId, String psName, String newPortId) {
List<VlanBindings> vlanBindings = new ArrayList<>();
for (L2gatewayConnection l2GwConn : l2GwConns) {
L2gateway l2Gateway = L2GatewayConnectionUtils.getNeutronL2gateway(broker, l2GwConn.getL2gatewayId());
if (l2Gateway == null) {
LOG.error("L2Gateway with id {} is not present", l2GwConn.getL2gatewayId().getValue());
} else {
String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(l2GwConn.getNetworkId().getValue());
List<Devices> l2Devices = l2Gateway.getDevices();
for (Devices l2Device : l2Devices) {
String l2DeviceName = l2Device.getDeviceName();
if (l2DeviceName != null && l2DeviceName.equals(psName)) {
for (Interfaces deviceInterface : l2Device.getInterfaces()) {
if (deviceInterface.getInterfaceName().equals(newPortId)) {
if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {
vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(hwvtepNodeId, vlanId, logicalSwitchName));
}
} else {
// Use defaultVlanId (specified in L2GatewayConnection) if Vlan
// ID not specified at interface level.
Integer segmentationId = l2GwConn.getSegmentId();
int defaultVlanId = segmentationId != null ? segmentationId : 0;
vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(hwvtepNodeId, defaultVlanId, logicalSwitchName));
}
}
}
}
}
}
}
return vlanBindings;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings in project netvirt by opendaylight.
the class TerminationPointCmd method transform.
@Override
public TerminationPoint transform(InstanceIdentifier<Node> nodePath, TerminationPoint src) {
HwvtepPhysicalPortAugmentation augmentation = src.getAugmentation(HwvtepPhysicalPortAugmentation.class);
if (augmentation == null) {
return new TerminationPointBuilder(src).build();
}
String nodeIdVal = nodePath.firstKeyOf(Node.class).getNodeId().getValue();
int idx = nodeIdVal.indexOf("/physicalswitch");
if (idx > 0) {
nodeIdVal = nodeIdVal.substring(0, idx);
nodePath = HwvtepHAUtil.convertToInstanceIdentifier(nodeIdVal);
}
final InstanceIdentifier<Node> path = nodePath;
TerminationPointBuilder tpBuilder = new TerminationPointBuilder(src);
tpBuilder.removeAugmentation(HwvtepPhysicalPortAugmentation.class);
HwvtepPhysicalPortAugmentationBuilder tpAugmentationBuilder = new HwvtepPhysicalPortAugmentationBuilder(augmentation);
if (augmentation.getVlanBindings() != null && augmentation.getVlanBindings().size() > 0) {
tpAugmentationBuilder.setVlanBindings(augmentation.getVlanBindings().stream().map(vlanBindings -> {
VlanBindingsBuilder vlanBindingsBuilder = new VlanBindingsBuilder(vlanBindings);
vlanBindingsBuilder.setLogicalSwitchRef(HwvtepHAUtil.convertLogicalSwitchRef(vlanBindings.getLogicalSwitchRef(), path));
return vlanBindingsBuilder.build();
}).collect(Collectors.toList()));
}
tpBuilder.addAugmentation(HwvtepPhysicalPortAugmentation.class, tpAugmentationBuilder.build());
return tpBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings in project netvirt by opendaylight.
the class TerminationPointCmd method areEqual.
@Override
public boolean areEqual(TerminationPoint updated, TerminationPoint orig) {
if (!updated.getKey().equals(orig.getKey())) {
return false;
}
HwvtepPhysicalPortAugmentation updatedAugmentation = updated.getAugmentation(HwvtepPhysicalPortAugmentation.class);
HwvtepPhysicalPortAugmentation origAugmentation = orig.getAugmentation(HwvtepPhysicalPortAugmentation.class);
List<VlanBindings> up = updatedAugmentation != null ? updatedAugmentation.getVlanBindings() : null;
List<VlanBindings> or = origAugmentation != null ? origAugmentation.getVlanBindings() : null;
if (!areSameSize(up, or)) {
return false;
}
List<VlanBindings> added = diffOf(up, or, bindingsComparator);
if (added.size() != 0) {
return false;
}
List<VlanBindings> removed = diffOf(or, up, bindingsComparator);
if (removed.size() != 0) {
return false;
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings in project netvirt by opendaylight.
the class ElanL2GatewayUtils method deleteVlanBindingsFromL2GatewayDevice.
/**
* Delete vlan bindings from l2 gateway device.
*
* @param nodeId
* the node id
* @param hwVtepDevice
* the hw vtep device
* @param defaultVlanId
* the default vlan id
* @return the listenable future
*/
public ListenableFuture<Void> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice, Integer defaultVlanId) {
if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) {
String errMsg = "HwVtepDevice is null or interfaces are empty.";
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName());
return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
String phyPortName = deviceInterface.getInterfaceName();
if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {
HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, phyPortName, vlanId);
}
} else {
// Use defaultVlanId (specified in L2GatewayConnection) if Vlan
// ID not specified at interface level.
HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, phyPortName, defaultVlanId);
}
}
LOG.info("Deleted Hwvtep VlanBindings from config DS. NodeID: {}, hwVtepDevice: {}, defaultVlanId: {} ", nodeId.getValue(), hwVtepDevice, defaultVlanId);
});
}
Aggregations