Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.linkdiscovery.web; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.HashSet; |
| 5 | import java.util.Map; |
| 6 | import java.util.Set; |
| 7 | |
| 8 | import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService; |
| 9 | import net.floodlightcontroller.linkdiscovery.LinkInfo; |
| 10 | import net.floodlightcontroller.routing.Link; |
| 11 | |
| 12 | import org.restlet.resource.Get; |
| 13 | import org.restlet.resource.ServerResource; |
| 14 | |
| 15 | public 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 | } |