use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap in project netvirt by opendaylight.
the class NetvirtProviderTest method createNetworkMap.
private void createNetworkMap(String nwUuidStr, String subnetUuidStr, boolean storeSubnet, String portUuidStr) {
SubnetmapBuilder subnetBuilder = new SubnetmapBuilder();
if (!portUuidStr.isEmpty()) {
List<Uuid> portIdList = new ArrayList<>();
portIdList.add(new Uuid(portUuidStr));
subnetBuilder.setPortList(portIdList);
}
Uuid subnetUuid = new Uuid(subnetUuidStr);
subnetBuilder.setId(subnetUuid);
List<Uuid> subnetIdList = new ArrayList<>();
subnetIdList.add(subnetUuid);
NetworkMapBuilder nwMapBuilder = createNetworkMap(nwUuidStr);
nwMapBuilder.setSubnetIdList(subnetIdList);
storeNetworkMap(new Uuid(nwUuidStr), nwMapBuilder.build());
// Simulates NetworkMap has subnet list, but subnets dont exist
if (storeSubnet) {
storeSubnetMap(subnetUuid, subnetBuilder.build());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap in project netvirt by opendaylight.
the class NetvirtProvider method getLogicalInterfacesFromNeutronNetwork.
public List<String> getLogicalInterfacesFromNeutronNetwork(NeutronNetwork nw) {
InstanceIdentifier<NetworkMap> networkMapIdentifier = getNetworkMapIdentifier(new Uuid(nw.getNetworkUuid()));
NetworkMap networkMap = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier).orNull();
if (networkMap == null) {
LOG.warn("getLogicalInterfacesFromNeutronNetwork cant get NetworkMap for NW UUID [{}]", nw.getNetworkUuid());
return Collections.emptyList();
}
List<String> interfaces = new ArrayList<>();
List<Uuid> subnetUuidList = networkMap.getSubnetIdList();
if (subnetUuidList != null) {
for (Uuid subnetUuid : subnetUuidList) {
InstanceIdentifier<Subnetmap> subnetId = getSubnetMapIdentifier(subnetUuid);
Subnetmap subnet = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetId).orNull();
if (subnet == null) {
LOG.warn("getLogicalInterfacesFromNeutronNetwork cant get Subnetmap for NW UUID [{}] Subnet UUID " + "[{}]", nw.getNetworkUuid(), subnetUuid.getValue());
continue;
}
if (subnet.getPortList() == null || subnet.getPortList().isEmpty()) {
LOG.warn("getLogicalInterfacesFromNeutronNetwork No ports on Subnet: NW UUID [{}] Subnet UUID [{}]", nw.getNetworkUuid(), subnetUuid.getValue());
continue;
}
subnet.getPortList().forEach(portId -> interfaces.add(portId.getValue()));
}
}
return interfaces;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap in project netvirt by opendaylight.
the class DhcpServiceUtils method getSubnetIdsFromNetworkId.
public static List<Uuid> getSubnetIdsFromNetworkId(DataBroker broker, Uuid networkId) {
InstanceIdentifier id = buildNetworkMapIdentifier(networkId);
Optional<NetworkMap> optionalNetworkMap = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
if (optionalNetworkMap.isPresent()) {
return optionalNetworkMap.get().getSubnetIdList();
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap in project netvirt by opendaylight.
the class SubnetRoutePacketInHandler method getTargetSubnetForPacketOut.
// return only the first VPN subnetopdataentry
private static SubnetOpDataEntry getTargetSubnetForPacketOut(DataBroker broker, long elanTag, int ipAddress) {
ElanTagName elanInfo = VpnUtil.getElanInfoByElanTag(broker, elanTag);
if (elanInfo == null) {
LOG.error("{} getTargetDpnForPacketOut: Unable to retrieve ElanInfo for elanTag {}", LOGGING_PREFIX, elanTag);
return null;
}
Optional<NetworkMap> optionalNetworkMap = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildNetworkMapIdentifier(new Uuid(elanInfo.getName())));
if (!optionalNetworkMap.isPresent()) {
LOG.debug("{} getTargetDpnForPacketOut: No network map found for elan info {}", LOGGING_PREFIX, elanInfo.getName());
return null;
}
List<Uuid> subnetList = optionalNetworkMap.get().getSubnetIdList();
LOG.debug("{} getTargetDpnForPacketOut: Obtained subnetList as {} for network {}", LOGGING_PREFIX, subnetList, elanInfo.getName());
for (Uuid subnetId : subnetList) {
String vpnName = null;
Subnetmap sn = VpnUtil.getSubnetmapFromItsUuid(broker, subnetId);
if (sn != null && sn.getVpnId() != null) {
vpnName = sn.getVpnId().getValue();
}
if (vpnName == null) {
continue;
}
Optional<SubnetOpDataEntry> optionalSubs;
optionalSubs = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, VpnUtil.buildSubnetOpDataEntryInstanceIdentifier(subnetId));
if (!optionalSubs.isPresent()) {
continue;
}
SubnetOpDataEntry subOpEntry = optionalSubs.get();
if (subOpEntry.getNhDpnId() != null) {
LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {}", LOGGING_PREFIX, subnetId.getValue());
boolean match = NWUtil.isIpInSubnet(ipAddress, subOpEntry.getSubnetCidr());
LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {} matching {}", LOGGING_PREFIX, subnetId.getValue(), match);
if (match) {
return subOpEntry;
}
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap in project netvirt by opendaylight.
the class NeutronSubnetChangeListener method deleteSubnetToNetworkMapping.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void deleteSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
try {
InstanceIdentifier<NetworkMap> networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
Optional<NetworkMap> optionalNetworkMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
if (optionalNetworkMap.isPresent()) {
NetworkMapBuilder nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
if (subnetIdList.remove(subnetId)) {
if (subnetIdList.isEmpty()) {
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
LOG.debug("Deleted network node in NetworkMaps DS for subnet {} network {}", subnetId.getValue(), networkId.getValue());
} else {
nwMapBuilder.setSubnetIdList(subnetIdList);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
LOG.debug("Deleted subnet-network mapping for subnet {} network {}", subnetId.getValue(), networkId.getValue());
}
} else {
LOG.error("Subnet {} is not mapped to network {}", subnetId.getValue(), networkId.getValue());
}
} else {
LOG.error("network {} not present for subnet {} ", networkId, subnetId);
}
} catch (ReadFailedException | RuntimeException e) {
LOG.error("Delete subnet-network mapping failed for subnet {} network {}", subnetId.getValue(), networkId.getValue());
}
}
Aggregations