use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class BgpConfigurationManager method delVrf.
public boolean delVrf(String rd, AddressFamily addressFamily) {
if (addressFamily == null) {
LOG.error("delVrf: vrf {}, addressFamily invalid", rd);
return false;
}
delMultipaths(rd);
AddressFamiliesVrfBuilder adfBuilder = new AddressFamiliesVrfBuilder();
if (addressFamily.equals(AddressFamily.IPV4)) {
adfBuilder.setAfi((long) af_afi.AFI_IP.getValue());
adfBuilder.setSafi((long) af_safi.SAFI_MPLS_VPN.getValue());
} else if (addressFamily.equals(AddressFamily.IPV6)) {
adfBuilder.setAfi((long) af_afi.AFI_IPV6.getValue());
adfBuilder.setSafi((long) af_safi.SAFI_MPLS_VPN.getValue());
} else if (addressFamily.equals(AddressFamily.L2VPN)) {
adfBuilder.setAfi((long) af_afi.AFI_IP.getValue());
adfBuilder.setSafi((long) af_safi.SAFI_EVPN.getValue());
}
LOG.debug("delVrf: Received Delete VRF : rd:{}, address family: {} {}", rd, adfBuilder.getAfi(), adfBuilder.getSafi());
Vrfs vrfOriginal = bgpUtil.getVrfFromRd(rd);
if (vrfOriginal == null) {
LOG.error("delVrf: no vrf with existing rd {}. step aborted", rd);
return false;
}
InstanceIdentifier.InstanceIdentifierBuilder<Vrfs> iib = InstanceIdentifier.builder(Bgp.class).child(VrfsContainer.class).child(Vrfs.class, new VrfsKey(rd));
InstanceIdentifier<Vrfs> iid = iib.build();
@SuppressWarnings("static-access") InstanceIdentifier<Bgp> iid6 = iid.builder(Bgp.class).build().child(MultipathContainer.class).child(Multipath.class, new MultipathKey(adfBuilder.getAfi(), adfBuilder.getSafi())).create(Bgp.class);
InstanceIdentifierBuilder<Vrfs> iib3 = iid6.child(VrfsContainer.class).child(Vrfs.class, new VrfsKey(rd)).builder();
InstanceIdentifier<Vrfs> iidFinal = iib3.build();
// ** update or delete the vrfs with the rest of AddressFamilies already present in the last list
AddressFamiliesVrf adfToDel = adfBuilder.build();
List<AddressFamiliesVrf> adfListOriginal = new ArrayList<>(vrfOriginal.nonnullAddressFamiliesVrf().values());
List<AddressFamiliesVrf> adfListToRemoveFromOriginal = new ArrayList<>();
adfListOriginal.forEach(adf -> {
if (adf.equals(adfToDel)) {
adfListToRemoveFromOriginal.add(adfToDel);
return;
}
});
for (AddressFamiliesVrf adfToRemove : adfListToRemoveFromOriginal) {
adfListOriginal.remove(adfToRemove);
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, iid, vrfOriginal);
} catch (TransactionCommitFailedException e) {
LOG.error("delVrf: Error updating VRF to datastore", e);
throw new RuntimeException(e);
}
}
if (adfListOriginal.isEmpty()) {
LOG.debug("delVrf: delete iid: {}", iidFinal);
delete(iidFinal);
return true;
}
// not all is removed
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class BgpConfigurationManager method addAddressFamily.
public void addAddressFamily(String nbrIp, int afi, int safi) {
Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
InstanceIdentifier.InstanceIdentifierBuilder<AddressFamilies> iib = InstanceIdentifier.builder(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class, new NeighborsKey(nbrAddr)).child(AddressFamilies.class, new AddressFamiliesKey((long) afi, (long) safi));
InstanceIdentifier<AddressFamilies> iid = iib.build();
AddressFamilies dto = new AddressFamiliesBuilder().setPeerIp(nbrAddr).setAfi((long) afi).setSafi((long) safi).build();
update(iid, dto);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class BgpConfigurationManager method startConfig.
public void startConfig(String bgpHost, int thriftPort) {
InstanceIdentifier.InstanceIdentifierBuilder<ConfigServer> iib = InstanceIdentifier.builder(Bgp.class).child(ConfigServer.class);
InstanceIdentifier<ConfigServer> iid = iib.build();
Ipv4Address ipAddr = new Ipv4Address(bgpHost);
ConfigServer dto = new ConfigServerBuilder().setHost(ipAddr).setPort((long) thriftPort).build();
update(iid, dto);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class BgpConfigurationManager method startBgp.
public void startBgp(long as, String routerId, int spt, boolean fbit) {
IpAddress rid = routerId == null ? null : IpAddressBuilder.getDefaultInstance(routerId);
Long staleTime = (long) spt;
InstanceIdentifier.InstanceIdentifierBuilder<AsId> iib = InstanceIdentifier.builder(Bgp.class).child(AsId.class);
InstanceIdentifier<AsId> iid = iib.build();
AsId dto = new AsIdBuilder().setLocalAs(as).setRouterId(rid).setStalepathTime(staleTime).setAnnounceFbit(fbit).build();
update(iid, dto);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class BgpConfigurationManager method onUpdatePushRoute.
/* onUpdatePushRoute
* Get Stale fibDSWriter map, and compare current route/fibDSWriter entry.
* - Entry compare shall include NextHop, Label.
* - If entry matches: delete from STALE Map. NO Change to FIB Config DS.
* - If entry not found, add to FIB Config DS.
* - If entry found, but either Label/NextHop doesn't match.
* - Update FIB Config DS with modified values.
* - delete from Stale Map.
*/
public void onUpdatePushRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop, String macaddress, Uint32 label, Uint32 l2label, String routermac, af_afi afi) {
PrefixUpdateEvent prefixUpdateEvent = new PrefixUpdateEvent(protocolType, rd, prefix, plen, nextHop, macaddress, label, l2label, routermac, afi);
bgpUpdatesHistory.addToHistory(TransactionType.ADD, prefixUpdateEvent);
boolean addroute = false;
boolean macupdate = false;
Uint32 l3vni = Uint32.ZERO;
VrfEntry.EncapType encapType = VrfEntry.EncapType.Mplsgre;
if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
encapType = VrfEntry.EncapType.Vxlan;
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = bgpUtil.getVpnInstanceOpData(rd);
if (vpnInstanceOpDataEntry != null) {
if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
LOG.info("Got RT2 route for RD {} l3label {} l2label {} from tep {} with mac {} remote RD {}", vpnInstanceOpDataEntry.getVpnInstanceName(), label, l2label, nextHop, macaddress, rd);
addTepToElanDS(rd, nextHop, macaddress, l2label);
macupdate = true;
} else {
l3vni = vpnInstanceOpDataEntry.getL3vni();
}
} else {
LOG.error("No corresponding vpn instance found for rd {}. Aborting.", rd);
return;
}
}
if (!staledFibEntriesMap.isEmpty()) {
// restart Scenario, as MAP is not empty.
Map<String, Uint32> map = staledFibEntriesMap.get(rd);
if (map != null) {
String prefixNextHop = appendNextHopToPrefix(prefix + "/" + plen, nextHop);
Uint32 labelInStaleMap = map.get(prefixNextHop);
if (null == labelInStaleMap) {
// New Entry, which happened to be added during restart.
addroute = true;
} else {
map.remove(prefixNextHop);
if (isRouteModified(label, labelInStaleMap)) {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
// Existing entry, where in Label got modified during restart
addroute = true;
}
}
} else {
LOG.debug("rd {} map is null while processing prefix {} ", rd, prefix);
addroute = true;
}
} else {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
addroute = true;
}
if (macupdate) {
LOG.info("ADD: Adding Mac Fib entry rd {} mac{} nexthop {} l2vni {}", rd, macaddress, nextHop, l2label);
fibDSWriter.addMacEntryToDS(rd, macaddress, prefix, Collections.singletonList(nextHop), encapType, l2label, routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Mac Fib entry rd {} prefix {} nexthop {} label {}", rd, macaddress, nextHop, l2label);
} else if (addroute) {
LOG.info("ADD: Adding Fib entry rd {} prefix {} nexthop {} label {} afi {}", rd, prefix, nextHop, label, afi);
// TODO: modify addFibEntryToDS signature
List<String> nextHopList = Collections.singletonList(nextHop);
fibDSWriter.addFibEntryToDS(rd, prefix + "/" + plen, nextHopList, encapType, label, l3vni, routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Fib entry rd {} prefix {} nexthop {} label {}", rd, prefix, nextHop, label);
String vpnName = bgpUtil.getVpnNameFromRd(rd);
if (vpnName != null) {
vpnLinkService.leakRouteIfNeeded(vpnName, prefix, nextHopList, label, RouteOrigin.BGP, NwConstants.ADD_FLOW);
}
}
}
Aggregations