blob: 4cad18e61db608eea3479003880ffe25cb9f3638 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.linkdiscovery.web;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Map;
6import java.util.Set;
7
8import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
9import net.floodlightcontroller.linkdiscovery.LinkInfo;
10import net.floodlightcontroller.routing.Link;
11
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}