Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.linkdiscovery.web; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.HashSet; |
| 5 | import java.util.Map; |
Yuta HIGUCHI | 7dc5bb5 | 2013-10-14 15:55:21 -0700 | [diff] [blame] | 6 | import java.util.Map.Entry; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 7 | import java.util.Set; |
| 8 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService; |
| 10 | import net.onrc.onos.core.linkdiscovery.Link; |
| 11 | import net.onrc.onos.core.linkdiscovery.LinkInfo; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 12 | |
| 13 | import org.restlet.resource.Get; |
| 14 | import org.restlet.resource.ServerResource; |
| 15 | |
| 16 | public class LinksResource extends ServerResource { |
| 17 | |
| 18 | @Get("json") |
| 19 | public Set<LinkWithType> retrieve() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | ILinkDiscoveryService ld = (ILinkDiscoveryService) getContext().getAttributes(). |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | for (Entry<Link, LinkInfo> e : links.entrySet()) { |
Yuta HIGUCHI | 7dc5bb5 | 2013-10-14 15:55:21 -0700 | [diff] [blame] | 28 | Link link = e.getKey(); |
| 29 | LinkInfo info = e.getValue(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 30 | LinkWithType lwt = new LinkWithType(link, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | info.getSrcPortState(), |
| 32 | info.getDstPortState(), |
| 33 | ld.getLinkType(link, info)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 34 | returnLinkSet.add(lwt); |
| 35 | } |
| 36 | } |
| 37 | return returnLinkSet; |
| 38 | } |
| 39 | } |