use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method addSubnetRouteToFib.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private boolean addSubnetRouteToFib(String rd, String subnetIp, BigInteger nhDpnId, String nextHopIp, String vpnName, Long elanTag, long label, long l3vni, Uuid subnetId, boolean isBgpVpn, String networkName) {
Preconditions.checkNotNull(rd, LOGGING_PREFIX + " addSubnetRouteToFib: RouteDistinguisher cannot be null or empty!");
Preconditions.checkNotNull(subnetIp, LOGGING_PREFIX + " addSubnetRouteToFib: SubnetRouteIp cannot be null or empty!");
Preconditions.checkNotNull(vpnName, LOGGING_PREFIX + " addSubnetRouteToFib: vpnName cannot be null or empty!");
Preconditions.checkNotNull(elanTag, LOGGING_PREFIX + " addSubnetRouteToFib: elanTag cannot be null or empty!");
Preconditions.checkNotNull(label, LOGGING_PREFIX + " addSubnetRouteToFib: label cannot be null or empty!");
VrfEntry.EncapType encapType = VpnUtil.getEncapType(VpnUtil.isL3VpnOverVxLan(l3vni));
VpnPopulator vpnPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
LOG.info("{} addSubnetRouteToFib: Adding SubnetRoute fib entry for vpnName {}, subnetIP {}, elanTag {}", LOGGING_PREFIX, vpnName, subnetIp, elanTag);
L3vpnInput input = new L3vpnInput().setRouteOrigin(RouteOrigin.CONNECTED).setRd(rd).setVpnName(vpnName).setSubnetIp(subnetIp).setNextHopIp(nextHopIp).setL3vni(l3vni).setLabel(label).setElanTag(elanTag).setDpnId(nhDpnId).setEncapType(encapType).setNetworkName(networkName).setPrimaryRd(rd);
if (!isBgpVpn) {
vpnPopulator.populateFib(input, null);
return true;
}
Preconditions.checkNotNull(nextHopIp, LOGGING_PREFIX + "NextHopIp cannot be null or empty!");
VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), subnetIp), VpnUtil.getPrefixToInterface(nhDpnId, subnetId.getValue(), subnetIp, subnetId, Prefixes.PrefixCue.SubnetRoute));
vpnPopulator.populateFib(input, null);
try {
// BGP manager will handle withdraw and advertise internally if prefix
// already exist
bgpManager.advertisePrefix(rd, null, /*macAddress*/
subnetIp, Collections.singletonList(nextHopIp), encapType, label, l3vni, 0, /*l2vni*/
null);
} catch (Exception e) {
LOG.error("{} addSubnetRouteToFib: Subnet route not advertised for subnet {} subnetIp {} vpnName {} rd {} " + "with dpnid {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd, nhDpnId, e);
return false;
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method addSubnetRouteToFib.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private boolean addSubnetRouteToFib(String rd, String subnetIp, Uint64 nhDpnId, String nextHopIp, String vpnName, Long elanTag, Uint32 label, Uint32 l3vni, Uuid subnetId, boolean isBgpVpn, String networkName) {
requireNonNull(rd, LOGGING_PREFIX + " addSubnetRouteToFib: RouteDistinguisher cannot be null or empty!");
requireNonNull(subnetIp, LOGGING_PREFIX + " addSubnetRouteToFib: SubnetRouteIp cannot be null or empty!");
requireNonNull(vpnName, LOGGING_PREFIX + " addSubnetRouteToFib: vpnName cannot be null or empty!");
requireNonNull(elanTag, LOGGING_PREFIX + " addSubnetRouteToFib: elanTag cannot be null or empty!");
requireNonNull(label, LOGGING_PREFIX + " addSubnetRouteToFib: label cannot be null or empty!");
VrfEntry.EncapType encapType = VpnUtil.getEncapType(VpnUtil.isL3VpnOverVxLan(l3vni));
VpnPopulator vpnPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
LOG.info("{} addSubnetRouteToFib: Adding SubnetRoute fib entry for vpnName {}, subnetIP {}, elanTag {}", LOGGING_PREFIX, vpnName, subnetIp, elanTag);
L3vpnInput input = new L3vpnInput().setRouteOrigin(RouteOrigin.CONNECTED).setRd(rd).setVpnName(vpnName).setSubnetIp(subnetIp).setNextHopIp(nextHopIp).setL3vni(l3vni.longValue()).setLabel(label.longValue()).setElanTag(elanTag).setDpnId(nhDpnId).setEncapType(encapType).setNetworkName(networkName).setPrimaryRd(rd);
if (!isBgpVpn) {
vpnPopulator.populateFib(input, null);
return true;
}
requireNonNull(nextHopIp, LOGGING_PREFIX + "NextHopIp cannot be null or empty!");
vpnUtil.syncWrite(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnUtil.getVpnId(vpnName), subnetIp), VpnUtil.getPrefixToInterface(nhDpnId, subnetId.getValue(), subnetIp, Prefixes.PrefixCue.SubnetRoute));
vpnPopulator.populateFib(input, null);
try {
// BGP manager will handle withdraw and advertise internally if prefix
// already exist
bgpManager.advertisePrefix(rd, null, /*macAddress*/
subnetIp, Collections.singletonList(nextHopIp), encapType, label, l3vni, Uint32.ZERO, /*l2vni*/
null);
} catch (Exception e) {
LOG.error("{} addSubnetRouteToFib: Subnet route not advertised for subnet {} subnetIp {} vpnName {} rd {} " + "with dpnid {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd, nhDpnId, e);
return false;
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project bgpcep by opendaylight.
the class LinkstateNlriParser method serializeCommonParts.
private static void serializeCommonParts(final CLinkstateDestinationBuilder builder, final DataContainerNode<? extends PathArgument> linkstate) {
// serialize common parts
final Optional<DataContainerChild<? extends PathArgument, ?>> distinguisher = linkstate.getChild(DISTINGUISHER_NID);
if (distinguisher.isPresent()) {
builder.setDistinguisher(new RouteDistinguisher((BigInteger) distinguisher.get().getValue()));
}
final Optional<DataContainerChild<? extends PathArgument, ?>> protocolId = linkstate.getChild(PROTOCOL_ID_NID);
// DOM representation contains values as are in the model, not as are in generated enum
if (protocolId.isPresent()) {
builder.setProtocolId(ProtocolId.forValue(domProtocolIdValue((String) protocolId.get().getValue())));
}
final Optional<DataContainerChild<? extends PathArgument, ?>> identifier = linkstate.getChild(IDENTIFIER_NID);
if (identifier.isPresent()) {
builder.setIdentifier(new Identifier((BigInteger) identifier.get().getValue()));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project bgpcep by opendaylight.
the class RouteDistinguisherUtilTest method testAs4BRouteDistinguisher.
@Test
public void testAs4BRouteDistinguisher() {
final RouteDistinguisher expected = createRouteDistinguisher(2, ADMIN, ASSIGNED_NUMBER);
final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_4B_BYTES));
assertEquals(expected.getRdAs(), parsed.getRdAs());
final ByteBuf byteAggregator = Unpooled.buffer(AS_4B_BYTES.length);
RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
assertArrayEquals(AS_4B_BYTES, byteAggregator.array());
assertEquals(ADMIN + SEPARATOR + ASSIGNED_NUMBER, parsed.getRdAs().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher in project bgpcep by opendaylight.
the class RouteDistinguisherUtilTest method testParseRouteDistinguisher.
@Test
public void testParseRouteDistinguisher() {
final RouteDistinguisher expected = RouteDistinguisherUtil.parseRouteDistinguisher(ADMIN + SEPARATOR + ASSIGNED_NUMBER);
final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_4B_BYTES));
assertEquals(expected.getRdAs(), parsed.getRdAs());
final RouteDistinguisher expectedRD = RouteDistinguisherUtil.parseRouteDistinguisher(expected);
assertEquals(expectedRD.getRdAs(), parsed.getRdAs());
final RouteDistinguisher expectedObj = RouteDistinguisherUtil.parseRouteDistinguisher((Object) (ADMIN + SEPARATOR + ASSIGNED_NUMBER));
assertEquals(expectedObj.getRdAs(), parsed.getRdAs());
}
Aggregations