+ @Override
+ public void connectUni(String uniId) {
+ List<RetailSvcIdType> allIpvcs = MefServicesUtils.getAllIpvcsServiceIds(dataBroker);
+ allIpvcs = (allIpvcs != null) ? allIpvcs : Collections.emptyList();
+
+ for (RetailSvcIdType ipvcSerId : allIpvcs) {
+ InstanceIdentifier<Ipvc> ipvcId = MefServicesUtils.getIpvcInstanceIdentifier(ipvcSerId);
+ Ipvc ipvc = MefServicesUtils.getIpvc(dataBroker, ipvcId);
+ if (ipvc == null) {
+ Log.error("Inconsistent data for svcId {}", ipvcSerId);
+ continue;
+ }
+ List<Uni> toConnect = new ArrayList<>();
+
+ List<Uni> unis = (ipvc.getUnis() != null) ? ipvc.getUnis().getUni() : null;
+ unis = (unis != null) ? unis : Collections.emptyList();
+ for (Uni uni : unis) {
+ if (uni.getUniId().getValue().equals(uniId)) {
+ Log.info("Connecting Uni {} to svc id {}", uniId, ipvcSerId);
+ toConnect.add(uni);
+ break;
+ }
+ }
+
+ IpvcVpn operIpvcVpn = MefServicesUtils.getOperIpvcVpn(dataBroker, ipvcId);
+ if (operIpvcVpn == null) {
+ String instanceName = ipvc.getIpvcId().getValue();
+ final String vpnName = NetvirtVpnUtils.getUUidFromString(instanceName);
+ createVpnInstance(vpnName, ipvcId);
+ operIpvcVpn = MefServicesUtils.getOperIpvcVpn(dataBroker, ipvcId);
+ if (operIpvcVpn == null) {
+ Log.error("Ipvc {} hasn't been created as required, Nothing to reconnect", ipvcSerId);
+ return;
+ }
+ }
+ String vpnName = operIpvcVpn.getVpnId();
+ String rd = waitForRd(vpnName);
+ createUnis(vpnName, ipvcId, toConnect, rd);
+ }
+ }
+
+ @Override
+ public void disconnectUni(String uniId) {
+
+ List<RetailSvcIdType> allIpvcs = MefServicesUtils.getAllIpvcsServiceIds(dataBroker);
+ allIpvcs = (allIpvcs != null) ? allIpvcs : Collections.emptyList();
+
+ for (RetailSvcIdType ipvcSerId : allIpvcs) {
+ InstanceIdentifier<Ipvc> ipvcId = MefServicesUtils.getIpvcInstanceIdentifier(ipvcSerId);
+ Ipvc ipvc = MefServicesUtils.getIpvc(dataBroker, ipvcId);
+ if (ipvc == null) {
+ Log.error("Inconsistent data for svcId {}", ipvcSerId);
+ continue;
+ }
+ List<Uni> toRemove = new ArrayList<>();
+
+ List<Uni> unis = (ipvc.getUnis() != null) ? ipvc.getUnis().getUni() : null;
+ unis = (unis != null) ? unis : Collections.emptyList();
+ for (Uni uni : unis) {
+ if (uni.getUniId().getValue().equals(uniId)) {
+ Log.info("Disconnecting Uni {} from svc id {}", uniId, ipvcSerId);
+ toRemove.add(uni);
+ break;
+ }
+ }
+
+ IpvcVpn operIpvcVpn = MefServicesUtils.getOperIpvcVpn(dataBroker, ipvcId);
+ if (operIpvcVpn == null) {
+ Log.error("Ipvc {} hasn't been created as required, Nothing to disconnect", ipvcSerId);
+ return;
+ }
+ String vpnName = operIpvcVpn.getVpnId();
+
+ synchronized (vpnName.intern()) {
+ WriteTransaction tx = MdsalUtils.createTransaction(dataBroker);
+ removeUnis(ipvcId, operIpvcVpn, toRemove, tx);
+ MdsalUtils.commitTransaction(tx);
+ }
+ }
+ }
+