use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces in project netvirt by opendaylight.
the class VpnSubnetRouteHandlerTest method setupMocks.
private void setupMocks() {
nexthopIp = "10.1.1.25";
idKey = "100:1.10.1.1.24";
poolName = "vpnservices";
elanTag = 2L;
longId = Long.valueOf("100");
nodeConnectorId = buildNodeConnectorId(dpId, 2L);
ipAddress = IpAddressBuilder.getDefaultInstance(nexthopIp);
vpnIntfaces = new VpnInterfacesBuilder().setInterfaceName(interfaceName).setKey(new VpnInterfacesKey(interfaceName)).build();
List<VpnInterfaces> vpnInterfaces = new ArrayList<>();
final List<SubnetToDpn> subToDpn = new ArrayList<>();
final List<Uuid> portList = new ArrayList<>();
final List<PortOpDataEntry> listPortOpDataEntry = new ArrayList<>();
final List<TunnelEndPoints> tunnelEndPoints = new ArrayList<>();
List<Uuid> subnetIdList = new ArrayList<>();
subnetIdList.add(subnetId);
vpnInterfaces.add(vpnIntfaces);
lowerLayerIfList.add(nodeConnectorId.getValue());
portOp = new PortOpDataEntryBuilder().setDpnId(dpId).setKey(new PortOpDataEntryKey(tenantId.getValue())).setSubnetIds(subnetIdList).setPortId(tenantId.getValue()).build();
subnetToDpn = new SubnetToDpnBuilder().setDpnId(dpId).setKey(new SubnetToDpnKey(dpId)).setVpnInterfaces(vpnInterfaces).build();
allocateIdOutput = new AllocateIdOutputBuilder().setIdValue(longId).build();
allocateIdInput = new AllocateIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
subToDpn.add(subnetToDpn);
portList.add(portId);
listPortOpDataEntry.add(portOp);
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder ifaceBuilder = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder();
ifaceBuilder.setLowerLayerIf(lowerLayerIfList).setType(L2vlan.class).setAdminStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus.Up).setOperStatus(Interface.OperStatus.Up).setIfIndex(100).setKey(new InterfaceKey(interfaceName)).setName(interfaceName).setPhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress.getDefaultInstance("AA:AA:AA:AA:AA:AA"));
stateInterface = ifaceBuilder.build();
subnetOp = new SubnetOpDataEntryBuilder().setElanTag(elanTag).setNhDpnId(dpId).setSubnetCidr(subnetIp).setSubnetId(subnetId).setKey(new SubnetOpDataEntryKey(subnetId)).setVpnName(interfaceName).setVrfId(primaryRd).setSubnetToDpn(subToDpn).setRouteAdvState(TaskState.Advertised).build();
vpnInstance = new VpnInstanceBuilder().setVpnId(elanTag).setVpnInstanceName(interfaceName).setVrfId(interfaceName).setKey(new VpnInstanceKey(interfaceName)).build();
subnetmap = new SubnetmapBuilder().setSubnetIp(subnetIp).setId(subnetId).setNetworkId(portId).setKey(new SubnetmapKey(subnetId)).setRouterId(portId).setVpnId(subnetId).setTenantId(tenantId).setPortList(portList).build();
portOpData = new PortOpDataBuilder().setPortOpDataEntry(listPortOpDataEntry).build();
dpntePsInfo = new DPNTEPsInfoBuilder().setDPNID(dpId).setUp(true).setKey(new DPNTEPsInfoKey(dpId)).setTunnelEndPoints(tunnelEndPoints).build();
tunlEndPts = new TunnelEndPointsBuilder().setInterfaceName(interfaceName).setVLANID(10).setIpAddress(ipAddress).build();
tunnelEndPoints.add(tunlEndPts);
ipv4Family = new Ipv4FamilyBuilder().setRouteDistinguisher(routeDistinguishers).build();
vpnInstnce = new org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceBuilder().setKey(new org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey(interfaceName)).setVpnInstanceName(interfaceName).setIpv4Family(ipv4Family).build();
networks = new NetworksBuilder().setId(portId).setKey(new NetworksKey(portId)).build();
doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces in project netvirt by opendaylight.
the class TunnelInterfaceStateListener method handleTunnelEventForDPN.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTunnelEventForDPN(StateTunnelList stateTunnelList, TunnelAction tunnelAction) {
final BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
final String srcTepIp = String.valueOf(stateTunnelList.getSrcInfo().getTepIp().getValue());
String destTepIp = String.valueOf(stateTunnelList.getDstInfo().getTepIp().getValue());
String rd;
BigInteger remoteDpnId = null;
boolean isTepDeletedOnDpn = false;
LOG.info("handleTunnelEventForDPN: Handle tunnel event for srcDpn {} SrcTepIp {} DestTepIp {} ", srcDpnId, srcTepIp, destTepIp);
int tunTypeVal = getTunnelType(stateTunnelList);
LOG.trace("handleTunnelEventForDPN: tunTypeVal is {}", tunTypeVal);
try {
if (tunnelAction == TunnelAction.TUNNEL_EP_ADD) {
LOG.info("handleTunnelEventForDPN: Tunnel ADD event received for Dpn {} VTEP Ip {} destTepIp {}", srcDpnId, srcTepIp, destTepIp);
if (isTunnelInLogicalGroup(stateTunnelList)) {
return;
}
} else if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE) {
LOG.info("handleTunnelEventForDPN: Tunnel DELETE event received for Dpn {} VTEP Ip {} DestTepIp {}", srcDpnId, srcTepIp, destTepIp);
// When tunnel EP is deleted on a DPN , VPN gets two deletion event.
// One for a DPN on which tunnel EP was deleted and another for other-end DPN.
// Update the adj for the vpninterfaces for a DPN on which TEP is deleted.
// Update the adj & VRF for the vpninterfaces for a DPN on which TEP is deleted.
// Dont update the adj & VRF for vpninterfaces for a DPN on which TEP is not deleted.
String endpointIpForDPN = null;
try {
endpointIpForDPN = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Unable to resolve endpoint IP for srcDpn {}", srcDpnId);
/* this dpn does not have the VTEP */
endpointIpForDPN = null;
}
if (endpointIpForDPN == null) {
LOG.info("handleTunnelEventForDPN: Tunnel TEP is deleted on Dpn {} VTEP Ip {} destTepIp {}", srcDpnId, srcTepIp, destTepIp);
isTepDeletedOnDpn = true;
}
}
// Get the list of VpnInterfaces from Intf Mgr for a SrcDPN on which TEP is added/deleted
Future<RpcResult<GetDpnInterfaceListOutput>> result;
List<Interfaces> srcDpninterfacelist = new ArrayList<>();
List<Interfaces> destDpninterfacelist = new ArrayList<>();
try {
result = intfRpcService.getDpnInterfaceList(new GetDpnInterfaceListInputBuilder().setDpid(srcDpnId).build());
RpcResult<GetDpnInterfaceListOutput> rpcResult = result.get();
if (!rpcResult.isSuccessful()) {
LOG.error("handleTunnelEventForDPN: RPC Call to GetDpnInterfaceList for srcDpnid {} srcTepIp {}" + " destTepIP {} returned with Errors {}", srcDpnId, srcTepIp, destTepIp, rpcResult.getErrors());
} else {
srcDpninterfacelist = rpcResult.getResult().getInterfaces();
}
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList for srcDpnid {}" + " srcTepIp {} destTepIp {}", srcDpnId, srcTepIp, destTepIp, e);
}
// Get the list of VpnInterfaces from Intf Mgr for a destDPN only for internal tunnel.
if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
remoteDpnId = new BigInteger(stateTunnelList.getDstInfo().getTepDeviceId());
try {
result = intfRpcService.getDpnInterfaceList(new GetDpnInterfaceListInputBuilder().setDpid(remoteDpnId).build());
RpcResult<GetDpnInterfaceListOutput> rpcResult = result.get();
if (!rpcResult.isSuccessful()) {
LOG.error("handleTunnelEventForDPN: RPC Call to GetDpnInterfaceList for remoteDpnid {}" + " srcTepIP {} destTepIp {} returned with Errors {}", remoteDpnId, srcTepIp, destTepIp, rpcResult.getErrors());
} else {
destDpninterfacelist = rpcResult.getResult().getInterfaces();
}
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList" + " for remoteDpnid {} srcTepIp {} destTepIp {}", remoteDpnId, srcTepIp, destTepIp, e);
}
}
/*
* Iterate over the list of VpnInterface for a SrcDpn on which TEP is added or deleted and read the adj.
* Update the adjacencies with the updated nexthop.
*/
Iterator<Interfaces> interfacelistIter = srcDpninterfacelist.iterator();
Interfaces interfaces = null;
String intfName = null;
List<Uuid> subnetList = new ArrayList<>();
Map<Long, String> vpnIdRdMap = new HashMap<>();
Set<String> listVpnName = new HashSet<>();
while (interfacelistIter.hasNext()) {
interfaces = interfacelistIter.next();
if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
return;
}
intfName = interfaces.getInterfaceName();
VpnInterface vpnInterface = VpnUtil.getConfiguredVpnInterface(dataBroker, intfName);
if (vpnInterface != null && !Boolean.TRUE.equals(vpnInterface.isScheduledForRemove())) {
listVpnName.addAll(VpnHelper.getVpnInterfaceVpnInstanceNamesString(vpnInterface.getVpnInstanceNames()));
handleTunnelEventForDPNVpn(stateTunnelList, vpnIdRdMap, tunnelAction, isTepDeletedOnDpn, subnetList, TunnelEventProcessingMethod.POPULATESUBNETS, vpnInterface);
}
}
/*
* Iterate over the list of VpnInterface for destDPN and get the prefix .
* Create remote rule for each of those prefix on srcDPN.
*/
interfacelistIter = destDpninterfacelist.iterator();
while (interfacelistIter.hasNext()) {
interfaces = interfacelistIter.next();
if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
return;
}
intfName = interfaces.getInterfaceName();
VpnInterface vpnInterface = VpnUtil.getConfiguredVpnInterface(dataBroker, intfName);
if (vpnInterface != null) {
handleTunnelEventForDPNVpn(stateTunnelList, vpnIdRdMap, tunnelAction, isTepDeletedOnDpn, subnetList, TunnelEventProcessingMethod.MANAGEREMOTEROUTES, vpnInterface);
}
}
// Iterate over the VpnId-to-Rd map.
for (Map.Entry<Long, String> entry : vpnIdRdMap.entrySet()) {
Long vpnId = entry.getKey();
rd = entry.getValue();
if (tunnelAction == TunnelAction.TUNNEL_EP_ADD && tunTypeVal == VpnConstants.ITMTunnelLocType.External.getValue()) {
fibManager.populateExternalRoutesOnDpn(srcDpnId, vpnId, rd, srcTepIp, destTepIp);
} else if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && tunTypeVal == VpnConstants.ITMTunnelLocType.External.getValue()) {
fibManager.cleanUpExternalRoutesOnDpn(srcDpnId, vpnId, rd, srcTepIp, destTepIp);
}
}
if (listVpnName.size() >= 1) {
if (tunnelAction == TunnelAction.TUNNEL_EP_ADD) {
for (Uuid subnetId : subnetList) {
// Populate the List of subnets
vpnSubnetRouteHandler.updateSubnetRouteOnTunnelUpEvent(subnetId, srcDpnId);
}
}
if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && isTepDeletedOnDpn) {
for (Uuid subnetId : subnetList) {
// Populate the List of subnets
vpnSubnetRouteHandler.updateSubnetRouteOnTunnelDownEvent(subnetId, srcDpnId);
}
}
}
} catch (RuntimeException e) {
LOG.error("handleTunnelEventForDpn: Unable to handle the tunnel event for srcDpnId {} srcTepIp {}" + " remoteDpnId {} destTepIp {}", srcDpnId, srcTepIp, remoteDpnId, destTepIp, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces in project netvirt by opendaylight.
the class VpnServiceChainUtils method getAllVpnIfaceNames.
public static List<String> getAllVpnIfaceNames(DataBroker dataBroker, String vpnName) {
String vpnRd = getVpnRd(dataBroker, vpnName);
InstanceIdentifier<VpnInstanceOpDataEntry> vpnOpDataIid = InstanceIdentifier.builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(vpnRd)).build();
try {
VpnInstanceOpDataEntry vpnOpData = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnOpDataIid);
if (vpnOpData == null) {
return Collections.emptyList();
}
List<VpnToDpnList> dpnToVpns = vpnOpData.getVpnToDpnList();
if (dpnToVpns == null) {
return Collections.emptyList();
}
return dpnToVpns.stream().filter(dpn -> dpn.getVpnInterfaces() != null).flatMap(dpn -> dpn.getVpnInterfaces().stream()).map(VpnInterfaces::getInterfaceName).collect(Collectors.toList());
} catch (ReadFailedException e) {
LOG.warn("getAllVpnInterfaces for vpn {}: Failure on read operation", vpnName, e);
return Collections.emptyList();
}
}
Aggregations