Obtaining the end host's MAC address and the device's ID

414 views
Skip to first unread message

JORDAN

unread,
Apr 20, 2015, 9:54:42 AM4/20/15
to onos...@onosproject.org
Hi, folks.

I'm trying to find out where a end host is connected to. To do this, I'm getting the src ConnectPoint and after that I get the deviceID and the hostId.
But the problem is: when I try to print the deviceID on Log, the deviceID is not shown (just whitespaces are printed where the deviceID should be. I attached a screenshot for better visualization). When I try to get the MAC address, I get the following exception: "java.lang.IllegalStateException: Connection point not associated with an end-station host"

Maybe a piece of code help you to understand where I'm stuck:

for (Link link : links) {
ConnectPoint src = link.src();
String deviceId = ((src.deviceId()).toString());
String macAddr = ((src.hostId().mac()).toString());

log.info("deviceId = ", deviceId);
log.info("macAddr = ", macAddr);
}

Is this the right way to obtain the device's ID and the end host's MAC address?
Thank you in advance.
log_tail_onos.png

Ali Al-Shabibi

unread,
Apr 20, 2015, 10:53:24 AM4/20/15
to JORDAN, onos...@onosproject.org
Hi Jordan,

Those lines:

log.info("deviceId = ", deviceId);
log.info("macAddr = ", macAddr);

Should be:

log.info("deviceId = {}", deviceId);
log.info("macAddr = {}", macAddr);

Note the {}. Otherwise the logger won't know where to print the variable you are passing. 

Hope this helps. 

--
Ali Al-Shabibi (sent from handheld)
--
You received this message because you are subscribed to the Google Groups "ONOS Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onos-dev+u...@onosproject.org.
To post to this group, send email to onos...@onosproject.org.
Visit this group at http://groups.google.com/a/onosproject.org/group/onos-dev/.
To view this discussion on the web visit https://groups.google.com/a/onosproject.org/d/msgid/onos-dev/21ae7332-584a-4a40-a577-159dcd4a78bc%40onosproject.org.
<log_tail_onos.png>

Thomas Vachuska

unread,
Apr 20, 2015, 11:09:54 AM4/20/15
to JORDAN, onos...@onosproject.org
Yes, what Ali said should make sure that you print the value correctly.

Regarding the easiest way to ascertain a location of the host, if you know the MAC & VLAN you should be able to access hostService.getHost(hostId(mac, vlanId)) or if you just know the MAC hostService.getHostsByMac(mac). Then, you should be able to use host.location() to get at the edge connection point, which contains the ID of the device and port number where the host is connected to the infrastructure.

Thomas

On Apr 20, 2015, at 6:54 AM, JORDAN <j...@icomp.ufam.edu.br> wrote:

JORDAN

unread,
Apr 20, 2015, 1:57:51 PM4/20/15
to onos...@onosproject.org, j...@icomp.ufam.edu.br
It worked for me.
Thank you.
Reply all
Reply to author
Forward
0 new messages