use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.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.linkstate.rev171207.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.linkstate.rev171207.RouteDistinguisher in project bgpcep by opendaylight.
the class RouteDistinguisherUtilTest method testAs2BLongRouteDistinguisher.
@Test
public void testAs2BLongRouteDistinguisher() {
final RouteDistinguisher expected = createRouteDistinguisher(0, ADMIN, ASSIGNED_NUMBER_BIG);
final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES_BIG));
assertEquals(expected.getRdTwoOctetAs(), parsed.getRdTwoOctetAs());
final ByteBuf byteAggregator = Unpooled.buffer(AS_2B_BYTES_BIG.length);
RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
assertArrayEquals(AS_2B_BYTES_BIG, byteAggregator.array());
assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER_BIG, parsed.getRdTwoOctetAs().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.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.linkstate.rev171207.RouteDistinguisher in project bgpcep by opendaylight.
the class RouteDistinguisherUtilTest method testAs2BRouteDistinguisher.
@Test
public void testAs2BRouteDistinguisher() {
final RouteDistinguisher expected = createRouteDistinguisher(0, ADMIN, ASSIGNED_NUMBER);
final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES));
assertEquals(expected.getRdTwoOctetAs(), parsed.getRdTwoOctetAs());
final ByteBuf byteAggregator = Unpooled.buffer(AS_2B_BYTES.length);
RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
assertArrayEquals(AS_2B_BYTES, byteAggregator.array());
assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER, parsed.getRdTwoOctetAs().getValue());
}
Aggregations