Comments (7)
Hi Joshua,
Currently there is no way of checking the status of a link in the dataplane without the intervention of the control-plane. In other words, the control plane needs to be made aware that a link changed status and then needs to update some state in the dataplane (either a table or a stateful register).
bmv2 broadcast port status changes on the nanomsg
notifications channel; it is also possible to query the status of a port through the Thrift RPC interface.
Different P4 architectures may or may not include a way to query the status of a port without involving the control-plane. It is possible than such an extern
object will be added to the bmv2 simple_switch
architecture in the upcoming months. But extern
objects are architecture-specific and therefore non-portable in general.
So the way you are doing it now is pretty much the only way as of today. bmv2 can notify you if a link goes down but you will need to handle this event in a separate process and update dataplane state yourself.
from behavioral-model.
Note that if you are interested in finding out how to receive these port events, let me know here and I can provide more details.
from behavioral-model.
Yes i'm very interested, would be great if you provide some details, thanks!
from behavioral-model.
bmv2 has three types of notifications: learning events, ageing events and port status events. They are broadcast from the switch using the nanomsg
messaging library. We provide a library, bmapps
, which lets you receive these notifications fairly easily. This library comes with this repo, so when you install simple_switch
, the bmapps
library should get installed as well.
This library defines a class, NotificationsListener
. You can find the header here: https://github.com/p4lang/behavioral-model/blob/master/include/bm/bm_apps/notifications.h
It is pretty straightforward to write a simple C++ program to receive the notifications. For example:
#include <bm/bm_apps/notifications.h>
#include <iostream>
#include <thread>
#include <chrono>
void port_callback(NotificationsListener::switch_id_t, int port_num,
NotificationsListener::PortEvent port_event, void *cookie) {
std::cout << "Event received for port " << port_num << "\n";
}
int main() {
NotificationsListener notifications;
notifications.register_port_event_cb(port_callback, nullptr);
notifications.start(); // start listening for notifications
// NotificationsListener::start() will create a new thread, but we can't let the "main" thread terminate
while(true) std::this_thread::sleep_for(std::chrono::seconds(100));
}
I apologize if there is a typo in the above code; I didn't try to compile it.
Of course you don't need to use this library, you can also subscribe directly to the nanomsg
socket. But then you will need to get familiar with nanomsg
and the message formats we use broadcast the notifications. If you don't want to write C++ code, this is what you will need to do (nanomsg
easily integrates with most programming languages).
from behavioral-model.
My C++ skills are really bad, so i tried to do it with the nanomsg approach.
First i used the nanomsg_client.py in /tools, on a link status change it produces a "Unknown type" output, so i wrote a little extension to support a link status change type.
So far i only get the status extracted (0 for down, 1 for up), but i wondered if there is some information about which port/neighbour/link is affected.
Is some kind if this information published via the message? Or where can i find the message formats you mentioned above?
from behavioral-model.
bmv2 publishes nanomsg notifications on 2 different sockets: one for dataplane even logging (e.g. table hit, ...), and one for events of interest to the control plane. The second one is the one we are discussing here (learning events, port events, table entry end-of-life events).
nanomsg_client.py
was written to decode and output the logging events received on the first socket. You can use this code as an inspiration, but in your case you want to receive messages on the second socket. The receiving part of the code will be the same (just make sure you use the correct socket address). As for the decoding, the 3 message formats (one for each event) can be found here as C structs: https://github.com/p4lang/behavioral-model/blob/master/src/bm_apps/notifications.cpp#L56. It should be straightforward to decode these in python using the struct
package (one again find inspiration in nanomsg_client.py
). Note that each message type is published under its own nanomsg PUB/SUB topic (LEA|
, AGE|
, PRT|
). If you are just interested in port events, you can just subscribe to PRT|
(instead of subscribing to all topics).
from behavioral-model.
Thanks again for the tips!
from behavioral-model.
Related Issues (20)
- import thrift
- TCP packets seem not to be processed correctly by bmv2 HOT 2
- Problem using multicast in runtime HOT 1
- Empty action-parameter vector is always accessed in ActionFnEntry::execute HOT 3
- How to build behavioral-model on the MacOS(Apple M1 Pro(13.5)) HOT 1
- How to track fileds of metadata with p4dbg? HOT 2
- Approximate conversion of bmv2 p4 performance to hardware performance HOT 3
- Applying the same table twice HOT 2
- Required to set forwarding pipeline before using the dataplane for streaming packets HOT 10
- Update project to require C++17 HOT 9
- Race conditions when passing in a BMv2 JSON config HOT 12
- To Add PNA support into BMv2. HOT 5
- How to build simple_switch / simple_switch_grpc on Ubuntu 24.04 ? HOT 4
- Why bmi_port.c is a C code? HOT 2
- Race conditions when processing packet in the egress pipeline. HOT 6
- Heap Buffer Overflow when installing many table entries HOT 1
- CMake support HOT 2
- Queue metadata with multiqueue HOT 2
- Where is the original p4 source code for recirc.json HOT 8
- Consider implementing something like Tuple Space Search for ternary table lookups
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from behavioral-model.