blob: 81c0b9efca6bab8e6dc2a8cf726972b2b7067fb6 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.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
Jonathan Hart23701d12014-04-03 10:45:48 -07009import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService;
10import net.onrc.onos.core.linkdiscovery.Link;
11import net.onrc.onos.core.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() {
Ray Milkey269ffb92014-04-03 14:43:30 -070020 ILinkDiscoveryService ld = (ILinkDiscoveryService) getContext().getAttributes().
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080021 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());
Ray Milkey269ffb92014-04-03 14:43:30 -070027 for (Entry<Link, LinkInfo> e : links.entrySet()) {
Yuta HIGUCHI7dc5bb52013-10-14 15:55:21 -070028 Link link = e.getKey();
29 LinkInfo info = e.getValue();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080030 LinkWithType lwt = new LinkWithType(link,
Ray Milkey269ffb92014-04-03 14:43:30 -070031 info.getSrcPortState(),
32 info.getDstPortState(),
33 ld.getLinkType(link, info));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080034 returnLinkSet.add(lwt);
35 }
36 }
37 return returnLinkSet;
38 }
39}