Git Product home page Git Product logo

Comments (7)

antoninbas avatar antoninbas commented on July 20, 2024

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.

antoninbas avatar antoninbas commented on July 20, 2024

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.

holidayfun avatar holidayfun commented on July 20, 2024

Yes i'm very interested, would be great if you provide some details, thanks!

from behavioral-model.

antoninbas avatar antoninbas commented on July 20, 2024

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.

holidayfun avatar holidayfun commented on July 20, 2024

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.

antoninbas avatar antoninbas commented on July 20, 2024

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.

holidayfun avatar holidayfun commented on July 20, 2024

Thanks again for the tips!

from behavioral-model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.