Aruba Apps

Reply
Occasional Contributor I

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

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

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

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

--
If you have urgent issues, please contact your Aruba partner or Aruba TAC (click for contact details).
Occasional Contributor I

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

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 

Occasional Contributor I

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

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

New Contributor

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

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!

Occasional Contributor I

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

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 

Occasional Contributor I

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

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

Occasional Contributor I

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

Thanks alot Simon,

 

The ALEDemonstrator was very helpful.

 

:)

 

 

Thanks,

Fareed

New Contributor

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

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).

Occasional Contributor I

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

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"
}

Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: