blob: 3c97e6a84338087ba1b4b7067622fb4a9ef0d3dc [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;
Yuta HIGUCHI7dc5bb52013-10-14 15:55:21 -07006import java.util.Map.Entry;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08007import java.util.Set;
8
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08009import net.floodlightcontroller.routing.Link;
HIGUCHI Yutaa56fbde2013-06-17 14:26:05 -070010import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
11import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080012
13import org.restlet.resource.Get;
14import org.restlet.resource.ServerResource;
15
16public class LinksResource extends ServerResource {
17
18 @Get("json")
19 public Set<LinkWithType> retrieve() {
20 ILinkDiscoveryService ld = (ILinkDiscoveryService)getContext().getAttributes().
21 get(ILinkDiscoveryService.class.getCanonicalName());
22 Map<Link, LinkInfo> links = new HashMap<Link, LinkInfo>();
23 Set<LinkWithType> returnLinkSet = new HashSet<LinkWithType>();
24
25 if (ld != null) {
26 links.putAll(ld.getLinks());
Yuta HIGUCHI7dc5bb52013-10-14 15:55:21 -070027 for(Entry<Link, LinkInfo> e : links.entrySet()) {
28 Link link = e.getKey();
29 LinkInfo info = e.getValue();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080030 LinkWithType lwt = new LinkWithType(link,
31 info.getSrcPortState(),
32 info.getDstPortState(),
33 ld.getLinkType(link, info));
34 returnLinkSet.add(lwt);
35 }
36 }
37 return returnLinkSet;
38 }
39}