Aruba Apps

last person joined: 3 days ago 

The HPE Aruba Networking Apps board is designed to address questions, comments, and feature requests for all HPE Aruba Networking mobile Apps
Expand all | Collapse all

Sample java code for ALE feed reader (protobuf over ZMQ)

This thread has been viewed 38 times
  • 1.  Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Mar 16, 2016 09:44 AM

    Hello,

    We are doing some integration between our system and ALE server to read AP and subscriber related stats through protobuf over ZMQ. I wonder if I can get hold of any sample C or Java code to for the feed reader from ALE. We have tried to do the same using python and we are getting empty fields returned.

    Any hints would be helpful.

     

    thanks 

     

    Atif


    #ALE


  • 2.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    EMPLOYEE
    Posted Mar 17, 2016 07:02 AM

    Atif,

    I'm not a developer, there is a section ZeroMQ Application Sample code which seems 'C' to me in the ALE 2.0 User Guide that can be found here: https://support.arubanetworks.com/Documentation/tabid/77/DMXModule/512/EntryId/20583/Default.aspx

     

    Does this help you??

     

    What also may be useful is to see if ALE is generating events. That can be easily done with the feed-reader command on the ALE server:

     

    [root@ale ~]# /opt/ale/bin/feed-reader
    Attempting to 'connect' to endpoint: tcp://localhost:7779
    Connected to endpoint: tcp://localhost:7779
    Subscribed to topic: ""
    [1] Recv event with topic "presence"
    seq: 2547170
    timestamp: 1458212356
    op: OP_DELETE
    topic_seq: 112229
    

    If you you don't see events there, the ALE might nog get any data.. so make sure ALE is getting data first.

     

     

    Herman



  • 3.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Mar 18, 2016 04:58 PM

    Thanks Herman. I am using a python script to do the job.

    Things seem to be working right and we are able to connect and subscribe but we are gettting the data once and that's it. We are not seeing the data coming in consistently. We are using NULL security as far as ZMTP is concerned. 

     

    Has anyone got a working python script for this?

     

    Thanks 



  • 4.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Nov 10, 2016 11:54 AM
      |   view attached

    I'm in the same situation, but with PHP.... After two days of server configurations and proto file modifications (PHP need a proto3 version of the schema.proto, I've attached my version to this post) ... I'm now able to connect and subscribe to topic and I receive some event labeled as (ex: location\18:1d:1f:11:a1:fw ) ... but the next received zmq message is empty ... Like if data is hidden by an hidden security mechanism...

    Do we need to send auth data, config certs , achieve a tunnel between me dev server and the ale ?!?!?? or something else ? Aruba please give us more hints and documentation about how we are suppose to make this work !

    On your side, did you've been able to achieve something in Rubby ? I was thinking to give it a try with Java or Rubby... But I think my problem is not language related...

    I've got the feeling of deeping in nothing... the doc is, at my thougth , insuffisant to help developpers get things work...

    Here is my current PHP script to collect location feed message from ZMQ...

    $context = new \ZMQContext();
    $subscriber = new ZMQSocket($context, ZMQ::SOCKET_SUB);
    $subscriber->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, "location");
    
    $conn = $subscriber->connect("tcp://x.x.x.x:7779");
    
    while (true) {
    $adresse = $subscriber->recv();
    error_log($adresse);
    $contents = $subscriber->recv();
    // I've done this as the second recv function return an empty string as bytes
    error_log(vsprintf(str_repeat('%c', count($contents)), $contents));
    }
    
    /* ****** ERROR LOG OUTPUT ******
    [10-Nov-2016 16:08:02 UTC] location/18:1d:1f:11:a1:fw
    [10-Nov-2016 16:08:02 UTC]
    */ ****** ERROR LOG OUTPUT ******

     

     Simon Rousseau

    Attachment(s)

    zip
    schema_proto3.zip   7 KB 1 version


  • 5.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted May 09, 2017 12:48 PM
    import org.zeromq.ZMQ;
    import org.zeromq.ZMQ.Context;
    import org.zeromq.ZMQ.Socket;

    // class generated from ALE protobuf schema
    import com.aruba.ale.proto.Schema.nb_event;

    import com.google.common.primitives.Bytes;


    public class SampleAleFeedReader {

      public static void main(String[] args) throws IOException {
        Context context = ZMQ.context(1);

        Socket socket = context.socket(ZMQ.SUB);
        socket.connect("tcp://0.0.0.0:7779");
        // subscribe to all available topics
        socket.subscribe("".getBytes());

        byte[] currByte = null;
        String currentAddress = null;
        
        while (!Thread.currentThread().isInterrupted()) {
          currentAddress = socket.recvStr(0);
          currByte = socket.recv(0);

          while (socket.hasReceiveMore()) {
            System.out.println("multi-part zmq message ");
            byte[] moreBytes = socket.recv(0);
            currByte = Bytes.concat(currByte, moreBytes);
          }

          System.out.println(nb_event.parseFrom(currByte));
        }
      }
    }

    Here's a snippet that works for me!



  • 6.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 21, 2017 08:08 AM

    Hi dbenz,

     

    I'm unable to convert the bytes into a readable format. Can you please share your implementation of 

    System.out.println(nb_event.parseFrom(currByte));
    (com.aruba.ale.proto.Schema.nb_event);

    Thanks,

    Fareed 



  • 7.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 21, 2017 09:41 AM

    Hi Fareed,

    My current project code is currently bounded to somes copyrights... but ;)

    My best advices is to have a look at the ALEDemonstrator source code. This is an open source project published by Peter Thornycroft (Aruba employee). The source code is available there : https://github.com/pthornycroft/ALE-Demonstrator-2 .You can also download the app from the Google Play Store...

    I've been able to convert this android app functionnalities to a pure java project in a matter of less than a day of work! ** Without any prior knoweldge of Android app development... At least, with this code, you will get all what you need to figure it out what is goind wrong with your project!

    If you're not able to manage your bug with this example, just send me an email with the current output or error message of the code you've send in your previous post.


    Sincerely,

     

    Simon Rousseau, M. Sc.
    simon@rioh.io



  • 8.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 22, 2017 01:56 AM

    Thanks alot Simon,

     

    The ALEDemonstrator was very helpful.

     

    :)

     

     

    Thanks,

    Fareed



  • 9.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 22, 2017 06:12 AM

    Hi Fareed,

     

    regarding the implementation of

     

    System.out.println(nb_event.parseFrom(currByte));

    I didn't implement anything - the class nb_event is generated by the protobuf compiler (including the method parseFrom). So my steps were:

     

    1. compile the ALE protobuf schema file (.proto) to java
    2. include the generated classes in your java project
    3. use the method parseFrom as shown above

    Apart from that, I also had a look at the ALEDemonstrator, as well as at the code at the end of the ALE api documentation (which is C++, but still helpful).



  • 10.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 22, 2017 06:24 AM

    Hi Dbenz/Simon,

     

    I have compiled and parsed the output. My only problem now is that some data are not parsed properly. It could be some charset problems. 

     

     

    AleMsg.nb_event nb_event = AleMsg.nb_event.parseFrom(cByte);
    System.out.println(nb_event);

     

    Here is my output after parsing an nb_event:

     

    seq: 1459367
    timestamp: 1503396325
    op: OP_UPDATE
    topic_seq: 501
    source_id: "\000\f)1\341&"
    station {
    sta_eth_mac {
    addr: "0\aM\005\304?"
    }
    username: "+966556575585"
    role: "guest"
    bssid {
    addr: "\204\324~\275\246\220"
    }
    device_type: "Android"
    hashed_sta_eth_mac: "\336\231k\022\273\271\277\2672\324\252\304>J\344\0329\200Hc"
    11: "AP-205-Showroom"
    }



  • 11.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 22, 2017 09:13 AM

    Hi Fareed,

    Simple question: Does the output is the same if you check the nb_event variable content from a break point in your code and watch it content from your IDE debug window ? Probably yes... but I must ask you this before goind further...

    My main concern is that not all fields seems to be incorrectly interpreted... so its probably something with your protobuf parser for 1 or more specific data types... Missinterpreted fields are : source_id, sta_eth_mac, addr, username, hashed_sta_eth_mac... So, maybe you will need to place some break points to find what is going wrong...

    Simon Rousseau, M. Sc.,
    simon@rioh.io

     



  • 12.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 23, 2017 05:14 AM

    Hi simon,

     

    I have realized that the misrepresented fields are of type bytes in the schema and is generated as ByteString in the Java file. The actual data seems to be a Hex number.



  • 13.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 23, 2017 08:19 AM

    Hi Simon,

     

    I've solved the problem by converting the parsed bytestring to a HEX number.

     

    Thanks,

    Fareed



  • 14.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 23, 2017 08:36 AM

    Hi Fareed,

     

    I'm glad that you've finaly found a workaround !


    You will see, once you can read those ALE messages... your work will be a lot easier ;)

     


    Have a nice development time!

    Simon Rousseau, M. Sc.
    simon@rioh.io



  • 15.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 23, 2017 08:28 AM

    Hi Fareed,

     

    I'm not a Protobuf expert, so ... maybe the schema ByteString typing is an ok translation or this could also be a problem... I need to check!

     

    Could you try to replace your generated schema and parser files by those one in the ALEDemonstrator project... and see if you get the same Hex string ? (If it's not already done) If it's working with the ALEDemonstrator files... this will lead us to a problem with your generated Schema and parser files...

     

    Briefly, the fact that you have a problem with only one type of data make me think that there is a problem with your schema or your parser files...

     

    But, we need to be sure before trying to debug them ...

     

    By the way, could you tell us on which version of ALE you are working on ?

     

     

    Cheer's,

     

    Simon Rousseau, M. Sc.
    simon@rioh.io



  • 16.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 23, 2017 09:50 AM

    Hi Simon,

     

    I've crosschecked the with ALE Demostration schema and I'm getting the same data. The problem was that I was expecting the data as string while it was in hex value. So I converted the bytes of the ByteString to hex value. See the method below

     

     

    public static String bytesToHex(byte[] bytes) {
    	char[] hexArray = "0123456789ABCDEF".toCharArray();
    	char[] hexChars = new char[bytes.length * 2];
    	for (int j = 0; j < bytes.length; j++) {
    		int v = bytes[j] & 0xFF;
    		hexChars[j * 2] = hexArray[v >>> 4];
    		hexChars[j * 2 + 1] = hexArray[v & 0x0F];
    	}
    	return new String(hexChars);
    }

    And the output was the following: 

     

     

    My schema hashed mac

    B3557CF0E38F2D3DBC690DF89BCED9F4F058C987

    Ale schema hashed mac

     

     

    B3557CF0E38F2D3DBC690DF89BCED9F4F058C987

     

     

    I used the 2.0.0.12 version of ALE, (even though the API guide wasn't a big help, the ALE Demo. was) and the 3.4.0 Parser.



  • 17.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Aug 23, 2017 09:54 AM

    Thanks again for your help. 

     

    Merci,

    Fareed



  • 18.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Mar 19, 2020 12:11 PM

    Hi ive generated the protobuf and compiled the same snippet however my snippet doesnt print out any messages. Although I can see via ALE root that the IAP is sending zmq messages through 7779..



  • 19.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Jun 29, 2020 11:07 AM

    @mike102 are you subscribing to all events?. I've created a post maybe could help you. https://community.arubanetworks.com/t5/Location-Services/ALE-API-Publish-Subscribe-API/m-p/660344



  • 20.  RE: Sample java code for ALE feed reader (protobuf over ZMQ)

    Posted Nov 10, 2020 04:58 PM
    I have compiled and parsed the output. My only problem now is that some data are not parsed properly. It could be some charset problems. 

    ------------------------------

    Tutuapp 9Apps ShowBox