use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method onPortAddedToSubnet.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onPortAddedToSubnet(Subnetmap subnetmap, Uuid portId) {
Uuid subnetId = subnetmap.getId();
LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
// TODO(vivek): Change this to use more granularized lock at subnetId level
try {
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (!optionalSubs.isPresent()) {
LOG.info("{} onPortAddedToSubnet: Port {} is part of a subnet {} that is not in VPN, ignoring", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
return;
}
String vpnName = optionalSubs.get().getVpnName();
String subnetIp = optionalSubs.get().getSubnetCidr();
String rd = optionalSubs.get().getVrfId();
String routeAdvState = optionalSubs.get().getRouteAdvState().toString();
LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {} subnetIp {} vpnName {} rd {} " + "TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, null);
Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, portId.getValue());
if (intfState == null) {
// Interface State not yet available
return;
}
final BigInteger dpnId;
try {
dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
} catch (Exception e) {
LOG.error("{} onPortAddedToSubnet: Unable to obtain dpnId for interface {}. subnetroute inclusion" + " for this interface failed for subnet {} subnetIp {} vpn {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, e);
return;
}
if (dpnId.equals(BigInteger.ZERO)) {
LOG.error("{} onPortAddedToSubnet: Port {} is not assigned DPN yet, ignoring subnetRoute " + "inclusion for the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
return;
}
subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, dpnId);
if (intfState.getOperStatus() != OperStatus.Up) {
LOG.error("{} onPortAddedToSubnet: Port {} is not UP yet, ignoring subnetRoute inclusion for " + "the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
return;
}
LOG.debug("{} onPortAddedToSubnet: Port {} added. Updating the SubnetOpDataEntry node for subnet {} " + "subnetIp {} vpnName {} rd {} TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
SubnetToDpn subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, portId.getValue());
if (subDpn == null) {
LOG.error("{} onPortAddedToSubnet: subnet-to-dpn list is null for subnetId {}. portId {}, " + "vpnName {}, rd {}, subnetIp {}", LOGGING_PREFIX, subnetId.getValue(), portId.getValue(), vpnName, rd, subnetIp);
return;
}
SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
List<SubnetToDpn> subDpnList = subOpBuilder.getSubnetToDpn();
subDpnList.add(subDpn);
subOpBuilder.setSubnetToDpn(subDpnList);
if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
if (subOpBuilder.getNhDpnId() == null) {
// No nexthop selected yet, elect one now
electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
subnetId, subnetmap.getNetworkId(), true);
} else if (!VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue())) {
// Already nexthop has been selected, only publishing to bgp required, so publish to bgp
getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
}
}
SubnetOpDataEntry subOpEntry = subOpBuilder.build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
LOG.info("{} onPortAddedToSubnet: Updated subnetopdataentry to OP Datastore for port {} subnet {}" + " subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpBuilder.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
} catch (Exception ex) {
LOG.error("{} onPortAddedToSubnet: Updation of subnetOpEntry for port {} subnet {} falied", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), ex);
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
} catch (Exception e) {
LOG.error("{} onPortAddedToSubnet: Unable to handle port {} added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method updateSubnetRouteOnTunnelUpEvent.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateSubnetRouteOnTunnelUpEvent(Uuid subnetId, BigInteger dpnId) {
LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Subnet {} Dpn {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString());
try {
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (!optionalSubs.isPresent()) {
LOG.error("{} updateSubnetRouteOnTunnelUpEvent: SubnetOpDataEntry for subnet {} is not available", LOGGING_PREFIX, subnetId.getValue());
return;
}
LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Subnet {} subnetIp {} vpnName {} rd {} TaskState {}" + " lastTaskState {} Dpn {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getVrfId(), optionalSubs.get().getRouteAdvState(), optionalSubs.get().getLastAdvState(), dpnId.toString());
SubnetOpDataEntry subOpEntry = optionalSubs.get();
SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subOpEntry);
boolean isExternalSubnetVpn = VpnUtil.isExternalSubnetVpn(subOpEntry.getVpnName(), subnetId.getValue());
if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
if (subOpBuilder.getNhDpnId() == null) {
// No nexthop selected yet, elect one now
electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
subnetId, null, /*networkId*/
!isExternalSubnetVpn);
} else if (!isExternalSubnetVpn) {
// Already nexthop has been selected, only publishing to bgp required, so publish to bgp
getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
}
}
subOpEntry = subOpBuilder.build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Updated subnetopdataentry to OP Datastore tunnel up" + " on dpn {} for subnet {} subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, dpnId.toString(), subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpEntry.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
} catch (RuntimeException ex) {
LOG.error("{} updateSubnetRouteOnTunnelUpEvent: updating subnetRoute for subnet {} on dpn {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString(), ex);
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
} catch (RuntimeException e) {
LOG.error("{} updateSubnetRouteOnTunnelUpEvent: Unable to handle tunnel up event for subnetId {} dpnId {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class L3vpnOverMplsGrePopulator method populateFib.
@Override
public void populateFib(L3vpnInput input, WriteTransaction writeConfigTxn) {
if (input.getRouteOrigin() == RouteOrigin.CONNECTED) {
LOG.info("populateFib : Found SubnetRoute for subnet {} rd {}", input.getSubnetIp(), input.getPrimaryRd());
addSubnetRouteFibEntry(input);
return;
}
Adjacency nextHop = input.getNextHop();
long label = nextHop.getLabel();
String vpnName = input.getVpnName();
String primaryRd = input.getPrimaryRd();
String rd = input.getRd();
String nextHopIp = input.getNextHopIp();
VrfEntry.EncapType encapType = input.getEncapType();
LOG.info("populateFib : Found Interface Adjacency with prefix {} rd {}", nextHop.getIpAddress(), primaryRd);
List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(broker, vpnName);
long vpnId = VpnUtil.getVpnId(broker, vpnName);
// it is a valid case for nextHopIpAddress to be null
String nextHopIpAddress = nextHop.getIpAddress();
// and internalVpnForExtraRoute (where rd is DpnId)
if (VpnUtil.isEligibleForBgp(primaryRd, input.getVpnName(), input.getDpnId(), input.getNetworkName())) {
// the DpnId is set as rd in case of extra routes present in router based VPN
addToLabelMapper(label, input.getDpnId(), nextHopIpAddress, Arrays.asList(nextHopIp), vpnId, input.getInterfaceName(), null, false, primaryRd);
Objects.requireNonNull(input.getRouteOrigin(), "RouteOrigin is mandatory");
addPrefixToBGP(rd, primaryRd, null, /*macAddress*/
nextHopIpAddress, nextHopIp, encapType, label, 0, /*l3vni*/
input.getGatewayMac(), input.getRouteOrigin(), writeConfigTxn);
// TODO: ERT - check for VPNs importing my route
for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
String vpnRd = vpn.getVrfId();
if (vpnRd != null) {
fibManager.addOrUpdateFibEntry(vpnRd, null, /*macAddress*/
nextHopIpAddress, Arrays.asList(nextHopIp), encapType, (int) label, 0, /*l3vni*/
input.getGatewayMac(), null, /*parentVpnRd*/
RouteOrigin.SELF_IMPORTED, writeConfigTxn);
LOG.info("populateFib: Exported route with rd {} prefix {} nexthop {} label {}" + " to VPN {} for interface {} on dpn {}", vpnRd, nextHop.getIpAddress(), nextHopIp, label, vpn, input.getInterfaceName(), input.getDpnId());
}
}
} else {
// ### add FIB route directly
fibManager.addOrUpdateFibEntry(vpnName, null, /*macAddress*/
nextHopIpAddress, Arrays.asList(nextHopIp), encapType, (int) label, 0, /*l3vni*/
input.getGatewayMac(), null, /*parentVpnRd*/
input.getRouteOrigin(), writeConfigTxn);
LOG.info("populateFib: Added internal FIB entry for prefix {} nexthop {} label {}" + " to VPN {} for interface {} on dpn {}", nextHop.getIpAddress(), nextHopIp, label, vpnName, input.getInterfaceName(), input.getDpnId());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class L3vpnOverVxlanPopulator method populateFib.
@Override
public void populateFib(L3vpnInput input, WriteTransaction writeConfigTxn) {
if (input.getRouteOrigin() == RouteOrigin.CONNECTED) {
LOG.info("populateFib : Found SubnetRoute for subnet {} rd {}", input.getSubnetIp(), input.getPrimaryRd());
addSubnetRouteFibEntry(input);
return;
}
String rd = input.getRd();
String primaryRd = input.getPrimaryRd();
Adjacency nextHop = input.getNextHop();
LOG.info("populateFib : Found Interface Adjacency with prefix {} rd {}", nextHop.getIpAddress(), primaryRd);
if (!rd.equalsIgnoreCase(input.getVpnName()) && !rd.equals(input.getNetworkName())) {
Objects.requireNonNull(input.getRouteOrigin(), "populateFib: RouteOrigin is mandatory");
addPrefixToBGP(rd, primaryRd, nextHop.getMacAddress(), nextHop.getIpAddress(), input.getNextHopIp(), input.getEncapType(), 0, /*label*/
input.getL3vni(), input.getGatewayMac(), input.getRouteOrigin(), writeConfigTxn);
} else {
LOG.error("Internal VPN for L3 Over VxLAN is not supported. Aborting.");
return;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class DhcpNeutronPortListener method processArpResponderForElanDpns.
/**
* Handle(Add/Remove) ARP Responder for DHCP IP on all the DPNs when DHCP is
* enabled/disabled on subnet add or update or delete.
*
* @param port
* DHCP port for which ARP Responder flow to be added when dhcp
* flag is enabled on the subnet or DHCP port for which ARP
* Responder flow to be removed when dhcp flag is disabled on the
* Subnet
* @param arpResponderAction
* ARP Responder Action to be performed i.e., add or remove flow
*/
private void processArpResponderForElanDpns(Port port, Consumer<ArpResponderInput> arpResponderAction) {
java.util.Optional<String> ip4Address = DhcpServiceUtils.getIpV4Address(port);
if (!ip4Address.isPresent()) {
LOG.warn("There is no IPv4Address for port {}, not performing ARP responder add/remove flow operation", port.getName());
return;
}
ElanHelper.getDpnInterfacesInElanInstance(broker, port.getNetworkId().getValue()).stream().map(ifName -> DhcpServiceUtils.getInterfaceInfo(interfaceManager, ifName)).forEach(interfaceInfo -> {
ArpResponderInput arpResponderInput = new ArpResponderInput.ArpReponderInputBuilder().setDpId(interfaceInfo.getDpId()).setInterfaceName(interfaceInfo.getInterfaceName()).setLportTag(interfaceInfo.getInterfaceTag()).setSha(port.getMacAddress().getValue()).setSpa(ip4Address.get()).build();
arpResponderAction.accept(arpResponderInput);
});
}
Aggregations