blob: c522a05a70136dbb3ca515a6685d57cc80a807fd [file] [log] [blame]
HIGUCHI Yutaa56fbde2013-06-17 14:26:05 -07001package net.onrc.onos.ofcontroller.linkdiscovery.web;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08002
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Map;
6import java.util.Set;
7
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08008import net.floodlightcontroller.routing.Link;
HIGUCHI Yutaa56fbde2013-06-17 14:26:05 -07009import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
10import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080011
12import org.restlet.resource.Get;
13import org.restlet.resource.ServerResource;
14
15public class LinksResource extends ServerResource {
16
17 @Get("json")
18 public Set<LinkWithType> retrieve() {
19 ILinkDiscoveryService ld = (ILinkDiscoveryService)getContext().getAttributes().
20 get(ILinkDiscoveryService.class.getCanonicalName());
21 Map<Link, LinkInfo> links = new HashMap<Link, LinkInfo>();
22 Set<LinkWithType> returnLinkSet = new HashSet<LinkWithType>();
23
24 if (ld != null) {
25 links.putAll(ld.getLinks());
26 for (Link link: links.keySet()) {
27 LinkInfo info = links.get(link);
28 LinkWithType lwt = new LinkWithType(link,
29 info.getSrcPortState(),
30 info.getDstPortState(),
31 ld.getLinkType(link, info));
32 returnLinkSet.add(lwt);
33 }
34 }
35 return returnLinkSet;
36 }
37}