use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.
the class ElanPacketInHandler method onPacketReceived.
@Override
public void onPacketReceived(PacketReceived notification) {
Class<? extends PacketInReason> pktInReason = notification.getPacketInReason();
short tableId = notification.getTableId().getValue();
if (pktInReason == NoMatch.class && tableId == NwConstants.ELAN_SMAC_TABLE) {
ElanManagerCounters.unknown_smac_pktin_rcv.inc();
try {
byte[] data = notification.getPayload();
Ethernet res = new Ethernet();
res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
byte[] srcMac = res.getSourceMACAddress();
final String macAddress = NWUtil.toStringMacAddress(srcMac);
final BigInteger metadata = notification.getMatch().getMetadata().getMetadata();
final long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
Optional<IfIndexInterface> interfaceInfoOp = elanUtils.getInterfaceInfoByInterfaceTag(portTag);
if (!interfaceInfoOp.isPresent()) {
LOG.warn("There is no interface for given portTag {}", portTag);
return;
}
String interfaceName = interfaceInfoOp.get().getInterfaceName();
LOG.debug("Received a packet with srcMac: {} ElanTag: {} PortTag: {} InterfaceName: {}", macAddress, elanTag, portTag, interfaceName);
ElanTagName elanTagName = elanUtils.getElanInfoByElanTag(elanTag);
if (elanTagName == null) {
LOG.warn("not able to find elanTagName in elan-tag-name-map for elan tag {}", elanTag);
return;
}
ElanInterfaceMac elanInterfaceMac = elanUtils.getElanInterfaceMacByInterfaceName(interfaceName);
if (elanInterfaceMac == null) {
LOG.info("There is no ElanInterfaceForwardingEntryDS created for interface :{}", interfaceName);
return;
}
String elanName = elanTagName.getName();
PhysAddress physAddress = new PhysAddress(macAddress);
MacEntry oldMacEntry = elanUtils.getMacEntryForElanInstance(elanName, physAddress).orNull();
boolean isVlanOrFlatProviderIface = interfaceManager.isExternalInterface(interfaceName);
Optional<IpAddress> srcIpAddress = elanUtils.getSourceIpAddress(res);
MacEntry newMacEntry = null;
BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
if (!srcIpAddress.isPresent()) {
newMacEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress).setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp).setIsStaticAddress(false).build();
} else {
newMacEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress).setIpPrefix(srcIpAddress.get()).setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp).setIsStaticAddress(false).build();
}
if (srcIpAddress.isPresent()) {
String prefix = srcIpAddress.get().getIpv4Address().getValue();
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
evpnUtils.advertisePrefix(elanInstance, macAddress, prefix, interfaceName, interfaceInfo.getDpId());
}
enqueueJobForMacSpecificTasks(macAddress, elanTag, interfaceName, elanName, physAddress, oldMacEntry, newMacEntry, isVlanOrFlatProviderIface);
ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
if (interfaceInfo == null) {
LOG.trace("Interface:{} is not present under Config DS", interfaceName);
return;
}
enqueueJobForDPNSpecificTasks(macAddress, elanTag, interfaceName, physAddress, elanInstance, interfaceInfo, oldMacEntry, newMacEntry, isVlanOrFlatProviderIface);
} catch (PacketException e) {
LOG.error("Failed to decode packet: {}", notification, e);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.
the class ElanGroupListener method update.
@Override
protected void update(InstanceIdentifier<Group> identifier, Group original, Group update) {
LOG.trace("received group updated {}", update.getKey().getGroupId());
final BigInteger dpnId = getDpnId(identifier.firstKeyOf(Node.class).getId().getValue());
if (dpnId == null) {
return;
}
List<L2GatewayDevice> allDevices = ElanL2GwCacheUtils.getAllElanDevicesFromCache();
if (allDevices == null || allDevices.isEmpty()) {
LOG.trace("no elan devices present in cache {}", update.getKey().getGroupId());
return;
}
int expectedElanFootprint = 0;
final ElanInstance elanInstance = getElanInstanceFromGroupId(update);
if (elanInstance == null) {
LOG.trace("no elan instance is null {}", update.getKey().getGroupId());
return;
}
ConcurrentMap<String, L2GatewayDevice> devices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanInstance.getElanInstanceName());
if (devices == null || devices.isEmpty()) {
LOG.trace("no elan devices in elan cache {} {}", elanInstance.getElanInstanceName(), update.getKey().getGroupId());
return;
}
boolean updateGroup = false;
List<DpnInterfaces> dpns = elanUtils.getElanDPNByName(elanInstance.getElanInstanceName());
if (dpns.size() > 0) {
expectedElanFootprint += dpns.size();
} else {
updateGroup = true;
}
expectedElanFootprint += devices.size();
if (update.getBuckets() != null && update.getBuckets().getBucket() != null) {
if (update.getBuckets().getBucket().size() != expectedElanFootprint) {
updateGroup = true;
} else {
LOG.trace("no of buckets matched perfectly {} {}", elanInstance.getElanInstanceName(), update.getKey().getGroupId());
}
}
if (updateGroup) {
List<Bucket> bucketList = elanL2GatewayMulticastUtils.getRemoteBCGroupBuckets(elanInstance, null, dpnId, 0, elanInstance.getElanTag());
// remove local bcgroup bucket
expectedElanFootprint--;
if (bucketList.size() != expectedElanFootprint) {
// no point in retrying if not able to meet expected foot print
return;
}
LOG.trace("no of buckets mismatched {} {}", elanInstance.getElanInstanceName(), update.getKey().getGroupId());
elanClusterUtils.runOnlyInOwnerNode(elanInstance.getElanInstanceName(), "updating broadcast group", () -> {
elanL2GatewayMulticastUtils.setupElanBroadcastGroups(elanInstance, dpnId);
return null;
});
} else {
LOG.trace("no buckets in the update {} {}", elanInstance.getElanInstanceName(), update.getKey().getGroupId());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.
the class HwvtepPhysicalSwitchListener method updated.
/**
* Upon update checks if the tunnels Ip was null earlier and it got newly added.
* In that case simply call add.
* If not then check if Tunnel Ip has been updated from an old value to new value.
* If yes. delete old ITM tunnels of odl Tunnel Ipand add new ITM tunnels with new Tunnel
* IP then call added ().
*
* @param identifier iid
* @param phySwitchBefore ps Node before update
* @param phySwitchAfter ps Node after update
*/
@Override
protected void updated(InstanceIdentifier<PhysicalSwitchAugmentation> identifier, PhysicalSwitchAugmentation phySwitchBefore, PhysicalSwitchAugmentation phySwitchAfter) {
NodeId nodeId = getNodeId(identifier);
LOG.trace("Received PhysicalSwitch Update Event for node {}: PhysicalSwitch Before: {}, " + "PhysicalSwitch After: {}", nodeId.getValue(), phySwitchBefore, phySwitchAfter);
String psName = getPsName(identifier);
if (psName == null) {
LOG.error("Could not find the physical switch name for node {}", nodeId.getValue());
return;
}
L2GatewayDevice existingDevice = l2GatewayCache.get(psName);
LOG.info("Received physical switch {} update event for node {}", psName, nodeId.getValue());
InstanceIdentifier<Node> globalNodeIid = getManagedByNodeIid(identifier);
if (DEVICE_NOT_CACHED_OR_PARENT_CONNECTED.test(existingDevice, globalNodeIid)) {
if (TUNNEL_IP_AVAILABLE.test(phySwitchAfter)) {
added(identifier, phySwitchAfter);
}
} else {
if (!Objects.equals(phySwitchAfter.getTunnelIps(), phySwitchBefore.getTunnelIps()) && TUNNEL_IP_CHANGED.test(phySwitchAfter, existingDevice)) {
final String hwvtepId = existingDevice.getHwvtepNodeId();
elanClusterUtils.runOnlyInOwnerNode(existingDevice.getDeviceName(), "handling Physical Switch add create itm tunnels ", () -> {
LOG.info("Deleting itm tunnels for device {}", existingDevice.getDeviceName());
L2GatewayUtils.deleteItmTunnels(itmRpcService, hwvtepId, existingDevice.getDeviceName(), existingDevice.getTunnelIp());
// TODO remove these sleeps
Thread.sleep(10000L);
LOG.info("Creating itm tunnels for device {}", existingDevice.getDeviceName());
ElanL2GatewayUtils.createItmTunnels(dataBroker, itmRpcService, hwvtepId, psName, phySwitchAfter.getTunnelIps().get(0).getTunnelIpsKey());
return Collections.emptyList();
});
try {
// TODO remove the sleep by using better itm api to detect finish of prev op
Thread.sleep(20000L);
} catch (InterruptedException e) {
LOG.error("Interrupted ");
}
existingDevice.setTunnelIps(new HashSet<>());
added(identifier, phySwitchAfter);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.
the class MergeCommandsAggregator method mergeUpdate.
public void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, LogicalDatastoreType datastoreType, ReadWriteTransaction tx) {
if (mod == null) {
return;
}
Collection<DataObjectModification> modifications = mod.getModifiedChildren();
modifications.stream().filter(modification -> skipCopy.negate().test(datastoreType, modification.getDataType())).filter(modification -> commands.get(modification.getDataType()) != null).peek(modification -> LOG.debug("Received {} modification {} copy/delete to {}", datastoreType, modification, dstPath)).forEach(modification -> {
MergeCommand mergeCommand = commands.get(modification.getDataType());
boolean create = modification.getDataAfter() != null;
DataObject data = create ? modification.getDataAfter() : modification.getDataBefore();
InstanceIdentifier<DataObject> transformedId = mergeCommand.generateId(dstPath, data);
DataObject transformedItem = mergeCommand.transform(dstPath, data);
Optional<DataObject> existingDataOptional = null;
try {
existingDataOptional = tx.read(datastoreType, transformedId).checkedGet();
} catch (ReadFailedException ex) {
LOG.error("Failed to read data {} from {}", transformedId, datastoreType);
return;
}
String destination = datastoreType == CONFIGURATION ? "child" : "parent";
if (create) {
if (isDataUpdated(existingDataOptional, transformedItem)) {
LOG.debug("Copy to {} {} {}", destination, datastoreType, transformedId);
tx.put(datastoreType, transformedId, transformedItem, true);
} else {
LOG.debug("Data not updated skip copy to {}", transformedId);
}
} else {
if (existingDataOptional.isPresent()) {
LOG.debug("Delete from {} {} {}", destination, datastoreType, transformedId);
tx.delete(datastoreType, transformedId);
} else {
LOG.debug("Delete skipped for {}", transformedId);
}
}
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.
the class VpnInterfaceManager method getVpnsExportingMyRoute.
private List<VpnInstanceOpDataEntry> getVpnsExportingMyRoute(final String vpnName) {
List<VpnInstanceOpDataEntry> vpnsToExportRoute = new ArrayList<>();
String vpnRd = VpnUtil.getVpnRd(dataBroker, vpnName);
final VpnInstanceOpDataEntry vpnInstanceOpDataEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
if (vpnInstanceOpDataEntry == null) {
LOG.debug("getVpnsExportingMyRoute: Could not retrieve vpn instance op data for {}" + " to check for vpns exporting the routes", vpnName);
return vpnsToExportRoute;
}
Predicate<VpnInstanceOpDataEntry> excludeVpn = input -> {
if (input.getVpnInstanceName() == null) {
LOG.error("getVpnsExportingMyRoute.excludeVpn: Received vpn instance with rd {} without a name", input.getVrfId());
return false;
}
return !input.getVpnInstanceName().equals(vpnName);
};
Predicate<VpnInstanceOpDataEntry> matchRTs = input -> {
Iterable<String> commonRTs = VpnUtil.intersection(VpnUtil.getRts(vpnInstanceOpDataEntry, VpnTarget.VrfRTType.ImportExtcommunity), VpnUtil.getRts(input, VpnTarget.VrfRTType.ExportExtcommunity));
return Iterators.size(commonRTs.iterator()) > 0;
};
vpnsToExportRoute = VpnUtil.getAllVpnInstanceOpData(dataBroker).stream().filter(excludeVpn).filter(matchRTs).collect(Collectors.toList());
return vpnsToExportRoute;
}
Aggregations