alshabib

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

...@@ -11,6 +11,7 @@ import org.onlab.onos.net.Path; ...@@ -11,6 +11,7 @@ import org.onlab.onos.net.Path;
11 import org.onlab.onos.net.device.DeviceService; 11 import org.onlab.onos.net.device.DeviceService;
12 import org.onlab.onos.net.host.HostService; 12 import org.onlab.onos.net.host.HostService;
13 import org.onlab.onos.net.link.LinkService; 13 import org.onlab.onos.net.link.LinkService;
14 +import org.onlab.onos.net.path.PathService;
14 import org.onlab.onos.net.topology.Topology; 15 import org.onlab.onos.net.topology.Topology;
15 import org.onlab.onos.net.topology.TopologyGraph; 16 import org.onlab.onos.net.topology.TopologyGraph;
16 import org.onlab.onos.net.topology.TopologyService; 17 import org.onlab.onos.net.topology.TopologyService;
...@@ -28,6 +29,7 @@ import java.util.Map; ...@@ -28,6 +29,7 @@ import java.util.Map;
28 import java.util.Set; 29 import java.util.Set;
29 30
30 import static org.onlab.onos.net.DeviceId.deviceId; 31 import static org.onlab.onos.net.DeviceId.deviceId;
32 +import static org.onlab.onos.net.HostId.hostId;
31 import static org.onlab.onos.net.PortNumber.portNumber; 33 import static org.onlab.onos.net.PortNumber.portNumber;
32 34
33 /** 35 /**
...@@ -99,12 +101,11 @@ public class TopologyResource extends BaseResource { ...@@ -99,12 +101,11 @@ public class TopologyResource extends BaseResource {
99 @Produces("application/json") 101 @Produces("application/json")
100 public Response paths(@PathParam("src") String src, @PathParam("dst") String dst) { 102 public Response paths(@PathParam("src") String src, @PathParam("dst") String dst) {
101 ObjectMapper mapper = new ObjectMapper(); 103 ObjectMapper mapper = new ObjectMapper();
102 - 104 + PathService pathService = get(PathService.class);
103 - TopologyService topologyService = get(TopologyService.class); 105 + Set<Path> paths = pathService.getPaths(elementId(src), elementId(dst));
104 - Topology topology = topologyService.currentTopology();
105 106
106 ArrayNode pathsNode = mapper.createArrayNode(); 107 ArrayNode pathsNode = mapper.createArrayNode();
107 - for (Path path : topologyService.getPaths(topology, deviceId(src), deviceId(dst))) { 108 + for (Path path : paths) {
108 pathsNode.add(json(mapper, path)); 109 pathsNode.add(json(mapper, path));
109 } 110 }
110 111
...@@ -114,6 +115,11 @@ public class TopologyResource extends BaseResource { ...@@ -114,6 +115,11 @@ public class TopologyResource extends BaseResource {
114 return Response.ok(rootNode.toString()).build(); 115 return Response.ok(rootNode.toString()).build();
115 } 116 }
116 117
118 + // Creates either device ID or host ID as appropriate.
119 + private ElementId elementId(String id) {
120 + return id.startsWith("nic:") ? hostId(id) : deviceId(id);
121 + }
122 +
117 // Scan all links and counts number of them between the same devices 123 // Scan all links and counts number of them between the same devices
118 // using a normalized link key. 124 // using a normalized link key.
119 private Map<String, AggLink> aggregateLinks() { 125 private Map<String, AggLink> aggregateLinks() {
......
...@@ -23,8 +23,8 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink { ...@@ -23,8 +23,8 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink {
23 */ 23 */
24 public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint, 24 public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint,
25 HostLocation hostLocation, boolean isIngress) { 25 HostLocation hostLocation, boolean isIngress) {
26 - super(providerId, isIngress ? hostLocation : hostPoint, 26 + super(providerId, isIngress ? hostPoint : hostLocation,
27 - isIngress ? hostPoint : hostLocation, Type.EDGE); 27 + isIngress ? hostLocation : hostPoint, Type.EDGE);
28 checkArgument(hostPoint.elementId() instanceof HostId, 28 checkArgument(hostPoint.elementId() instanceof HostId,
29 "Host point does not refer to a host ID"); 29 "Host point does not refer to a host ID");
30 this.hostId = (HostId) hostPoint.elementId(); 30 this.hostId = (HostId) hostPoint.elementId();
......
...@@ -44,7 +44,7 @@ public final class HostId extends ElementId { ...@@ -44,7 +44,7 @@ public final class HostId extends ElementId {
44 */ 44 */
45 public static HostId hostId(MACAddress mac, VLANID vlanId) { 45 public static HostId hostId(MACAddress mac, VLANID vlanId) {
46 // FIXME: use more efficient means of encoding 46 // FIXME: use more efficient means of encoding
47 - return hostId("nic" + ":" + mac + "/" + vlanId); 47 + return hostId("nic" + ":" + mac + "-" + vlanId);
48 } 48 }
49 49
50 /** 50 /**
......
1 +package org.onlab.onos.net.path;
2 +
3 +import org.onlab.onos.net.ElementId;
4 +import org.onlab.onos.net.Path;
5 +import org.onlab.onos.net.topology.LinkWeight;
6 +
7 +import java.util.Set;
8 +
9 +/**
10 + * Service for obtaining pre-computed paths or for requesting computation of
11 + * paths using the current topology snapshot.
12 + */
13 +public interface PathService {
14 +
15 + /**
16 + * Returns the set of all shortest paths, precomputed in terms of hop-count,
17 + * between the specified source and destination elements.
18 + *
19 + * @param src source element
20 + * @param dst destination element
21 + * @return set of all shortest paths between the two elements
22 + */
23 + Set<Path> getPaths(ElementId src, ElementId dst);
24 +
25 + /**
26 + * Returns the set of all shortest paths, computed using the supplied
27 + * edge-weight entity, between the specified source and destination
28 + * network elements.
29 + *
30 + * @param src source element
31 + * @param dst destination element
32 + * @return set of all shortest paths between the two element
33 + */
34 + Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight);
35 +
36 +}
...@@ -47,8 +47,8 @@ public class DefaultEdgeLinkTest { ...@@ -47,8 +47,8 @@ public class DefaultEdgeLinkTest {
47 public void basics() { 47 public void basics() {
48 HostLocation hostLocation = new HostLocation(DID1, P1, 123L); 48 HostLocation hostLocation = new HostLocation(DID1, P1, 123L);
49 EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false); 49 EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false);
50 - assertEquals("incorrect src", cp(HID1, P0), link.src()); 50 + assertEquals("incorrect src", cp(HID1, P0), link.dst());
51 - assertEquals("incorrect dst", hostLocation, link.dst()); 51 + assertEquals("incorrect dst", hostLocation, link.src());
52 assertEquals("incorrect type", Link.Type.EDGE, link.type()); 52 assertEquals("incorrect type", Link.Type.EDGE, link.type());
53 assertEquals("incorrect hostId", HID1, link.hostId()); 53 assertEquals("incorrect hostId", HID1, link.hostId());
54 assertEquals("incorrect connect point", hostLocation, link.hostLocation()); 54 assertEquals("incorrect connect point", hostLocation, link.hostLocation());
......
...@@ -22,7 +22,7 @@ public class HostIdTest extends ElementIdTest { ...@@ -22,7 +22,7 @@ public class HostIdTest extends ElementIdTest {
22 @Test 22 @Test
23 public void basics() { 23 public void basics() {
24 new EqualsTester() 24 new EqualsTester()
25 - .addEqualityGroup(hostId("nic:00:11:00:00:00:01/11"), 25 + .addEqualityGroup(hostId("nic:00:11:00:00:00:01-11"),
26 hostId(MAC1, VLAN1)) 26 hostId(MAC1, VLAN1))
27 .addEqualityGroup(hostId(MAC2, VLAN2)) 27 .addEqualityGroup(hostId(MAC2, VLAN2))
28 .testEquals(); 28 .testEquals();
......
1 +package org.onlab.onos.net.device;
2 +
3 +import org.onlab.onos.net.Device;
4 +import org.onlab.onos.net.DeviceId;
5 +import org.onlab.onos.net.MastershipRole;
6 +import org.onlab.onos.net.Port;
7 +import org.onlab.onos.net.PortNumber;
8 +
9 +import java.util.List;
10 +
11 +/**
12 + * Test adapter for device service.
13 + */
14 +public class DeviceServiceAdapter implements DeviceService {
15 + @Override
16 + public int getDeviceCount() {
17 + return 0;
18 + }
19 +
20 + @Override
21 + public Iterable<Device> getDevices() {
22 + return null;
23 + }
24 +
25 + @Override
26 + public Device getDevice(DeviceId deviceId) {
27 + return null;
28 + }
29 +
30 + @Override
31 + public MastershipRole getRole(DeviceId deviceId) {
32 + return null;
33 + }
34 +
35 + @Override
36 + public List<Port> getPorts(DeviceId deviceId) {
37 + return null;
38 + }
39 +
40 + @Override
41 + public Port getPort(DeviceId deviceId, PortNumber portNumber) {
42 + return null;
43 + }
44 +
45 + @Override
46 + public boolean isAvailable(DeviceId deviceId) {
47 + return false;
48 + }
49 +
50 + @Override
51 + public void addListener(DeviceListener listener) {
52 + }
53 +
54 + @Override
55 + public void removeListener(DeviceListener listener) {
56 + }
57 +
58 +}
1 +package org.onlab.onos.net.host;
2 +
3 +import org.onlab.onos.net.ConnectPoint;
4 +import org.onlab.onos.net.DeviceId;
5 +import org.onlab.onos.net.Host;
6 +import org.onlab.onos.net.HostId;
7 +import org.onlab.packet.IPAddress;
8 +import org.onlab.packet.MACAddress;
9 +import org.onlab.packet.VLANID;
10 +
11 +import java.util.Set;
12 +
13 +/**
14 + * Test adapter for host service.
15 + */
16 +public class HostServiceAdapter implements HostService {
17 + @Override
18 + public int getHostCount() {
19 + return 0;
20 + }
21 +
22 + @Override
23 + public Iterable<Host> getHosts() {
24 + return null;
25 + }
26 +
27 + @Override
28 + public Host getHost(HostId hostId) {
29 + return null;
30 + }
31 +
32 + @Override
33 + public Set<Host> getHostsByVlan(VLANID vlanId) {
34 + return null;
35 + }
36 +
37 + @Override
38 + public Set<Host> getHostsByMac(MACAddress mac) {
39 + return null;
40 + }
41 +
42 + @Override
43 + public Set<Host> getHostsByIp(IPAddress ip) {
44 + return null;
45 + }
46 +
47 + @Override
48 + public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
49 + return null;
50 + }
51 +
52 + @Override
53 + public Set<Host> getConnectedHosts(DeviceId deviceId) {
54 + return null;
55 + }
56 +
57 + @Override
58 + public void addListener(HostListener listener) {
59 + }
60 +
61 + @Override
62 + public void removeListener(HostListener listener) {
63 + }
64 +
65 +}
1 +package org.onlab.onos.net.link;
2 +
3 +import org.onlab.onos.net.ConnectPoint;
4 +import org.onlab.onos.net.DeviceId;
5 +import org.onlab.onos.net.Link;
6 +
7 +import java.util.Set;
8 +
9 +/**
10 + * Test adapter for link service.
11 + */
12 +public class LinkServiceAdapter implements LinkService {
13 + @Override
14 + public int getLinkCount() {
15 + return 0;
16 + }
17 +
18 + @Override
19 + public Iterable<Link> getLinks() {
20 + return null;
21 + }
22 +
23 + @Override
24 + public Set<Link> getDeviceLinks(DeviceId deviceId) {
25 + return null;
26 + }
27 +
28 + @Override
29 + public Set<Link> getDeviceEgressLinks(DeviceId deviceId) {
30 + return null;
31 + }
32 +
33 + @Override
34 + public Set<Link> getDeviceIngressLinks(DeviceId deviceId) {
35 + return null;
36 + }
37 +
38 + @Override
39 + public Set<Link> getLinks(ConnectPoint connectPoint) {
40 + return null;
41 + }
42 +
43 + @Override
44 + public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
45 + return null;
46 + }
47 +
48 + @Override
49 + public Set<Link> getIngressLinks(ConnectPoint connectPoint) {
50 + return null;
51 + }
52 +
53 + @Override
54 + public Link getLink(ConnectPoint src, ConnectPoint dst) {
55 + return null;
56 + }
57 +
58 + @Override
59 + public void addListener(LinkListener listener) {
60 + }
61 +
62 + @Override
63 + public void removeListener(LinkListener listener) {
64 + }
65 +
66 +}
1 +package org.onlab.onos.net.topology;
2 +
3 +import org.onlab.onos.net.ConnectPoint;
4 +import org.onlab.onos.net.DeviceId;
5 +import org.onlab.onos.net.Link;
6 +import org.onlab.onos.net.Path;
7 +
8 +import java.util.Set;
9 +
10 +/**
11 + * Test adapter for topology service.
12 + */
13 +public class TopologyServiceAdapter implements TopologyService {
14 + @Override
15 + public Topology currentTopology() {
16 + return null;
17 + }
18 +
19 + @Override
20 + public boolean isLatest(Topology topology) {
21 + return false;
22 + }
23 +
24 + @Override
25 + public TopologyGraph getGraph(Topology topology) {
26 + return null;
27 + }
28 +
29 + @Override
30 + public Set<TopologyCluster> getClusters(Topology topology) {
31 + return null;
32 + }
33 +
34 + @Override
35 + public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
36 + return null;
37 + }
38 +
39 + @Override
40 + public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
41 + return null;
42 + }
43 +
44 + @Override
45 + public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
46 + return null;
47 + }
48 +
49 + @Override
50 + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
51 + return null;
52 + }
53 +
54 + @Override
55 + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
56 + return null;
57 + }
58 +
59 + @Override
60 + public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
61 + return false;
62 + }
63 +
64 + @Override
65 + public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
66 + return false;
67 + }
68 +
69 + @Override
70 + public void addListener(TopologyListener listener) {
71 + }
72 +
73 + @Override
74 + public void removeListener(TopologyListener listener) {
75 + }
76 +
77 +}
1 +package org.onlab.onos.net.trivial.path;
2 +
3 +import com.google.common.collect.Lists;
4 +import com.google.common.collect.Sets;
5 +import org.apache.felix.scr.annotations.Activate;
6 +import org.apache.felix.scr.annotations.Component;
7 +import org.apache.felix.scr.annotations.Deactivate;
8 +import org.apache.felix.scr.annotations.Reference;
9 +import org.apache.felix.scr.annotations.ReferenceCardinality;
10 +import org.apache.felix.scr.annotations.Service;
11 +import org.onlab.onos.net.ConnectPoint;
12 +import org.onlab.onos.net.DefaultEdgeLink;
13 +import org.onlab.onos.net.DefaultPath;
14 +import org.onlab.onos.net.DeviceId;
15 +import org.onlab.onos.net.EdgeLink;
16 +import org.onlab.onos.net.ElementId;
17 +import org.onlab.onos.net.Host;
18 +import org.onlab.onos.net.HostId;
19 +import org.onlab.onos.net.HostLocation;
20 +import org.onlab.onos.net.Link;
21 +import org.onlab.onos.net.Path;
22 +import org.onlab.onos.net.PortNumber;
23 +import org.onlab.onos.net.host.HostService;
24 +import org.onlab.onos.net.path.PathService;
25 +import org.onlab.onos.net.provider.ProviderId;
26 +import org.onlab.onos.net.topology.LinkWeight;
27 +import org.onlab.onos.net.topology.Topology;
28 +import org.onlab.onos.net.topology.TopologyService;
29 +import org.slf4j.Logger;
30 +
31 +import java.util.List;
32 +import java.util.Set;
33 +
34 +import static com.google.common.base.Preconditions.checkNotNull;
35 +import static org.onlab.onos.net.DeviceId.deviceId;
36 +import static org.slf4j.LoggerFactory.getLogger;
37 +
38 +/**
39 + * Provides implementation of a path selection service atop the current
40 + * topology and host services.
41 + */
42 +@Component(immediate = true)
43 +@Service
44 +public class SimplePathManager implements PathService {
45 +
46 + private static final String ELEMENT_ID_NULL = "Element ID cannot be null";
47 +
48 + private static final ProviderId PID = new ProviderId("org.onlab.onos.core");
49 + private static final PortNumber P0 = PortNumber.portNumber(0);
50 +
51 + private static final EdgeLink NOT_HOST = new NotHost();
52 +
53 + private final Logger log = getLogger(getClass());
54 +
55 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 + protected TopologyService topologyService;
57 +
58 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 + protected HostService hostService;
60 +
61 + @Activate
62 + public void setUp() {
63 + log.info("Started");
64 + }
65 +
66 + @Deactivate
67 + public void tearDown() {
68 + log.info("Stopped");
69 + }
70 +
71 + @Override
72 + public Set<Path> getPaths(ElementId src, ElementId dst) {
73 + return getPaths(src, dst, null);
74 + }
75 +
76 + @Override
77 + public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
78 + checkNotNull(src, ELEMENT_ID_NULL);
79 + checkNotNull(dst, ELEMENT_ID_NULL);
80 +
81 + // Get the source and destination edge locations
82 + EdgeLink srcEdge = getEdgeLink(src, true);
83 + EdgeLink dstEdge = getEdgeLink(dst, false);
84 +
85 + DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
86 + DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;
87 +
88 + // If the source and destination are on the same edge device, there
89 + // is just one path, so build it and return it.
90 + if (srcDevice.equals(dstDevice)) {
91 + return edgeToEdgePaths(srcEdge, dstEdge);
92 + }
93 +
94 + // Otherwise get all paths between the source and destination edge
95 + // devices.
96 + Topology topology = topologyService.currentTopology();
97 + Set<Path> paths = weight == null ?
98 + topologyService.getPaths(topology, srcDevice, dstDevice) :
99 + topologyService.getPaths(topology, srcDevice, dstDevice, weight);
100 +
101 + return edgeToEdgePaths(srcEdge, dstEdge, paths);
102 + }
103 +
104 + // Finds the host edge link if the element ID is a host id of an existing
105 + // host. Otherwise, if the host does not exist, it returns null and if
106 + // the element ID is not a host ID, returns NOT_HOST edge link.
107 + private EdgeLink getEdgeLink(ElementId elementId, boolean isIngress) {
108 + if (elementId instanceof HostId) {
109 + // Resolve the host, return null.
110 + Host host = hostService.getHost((HostId) elementId);
111 + if (host == null) {
112 + return null;
113 + }
114 + return new DefaultEdgeLink(PID, new ConnectPoint(elementId, P0),
115 + host.location(), isIngress);
116 + }
117 + return NOT_HOST;
118 + }
119 +
120 + // Produces a set of direct edge-to-edge paths.
121 + private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink) {
122 + Set<Path> endToEndPaths = Sets.newHashSetWithExpectedSize(1);
123 + if (srcLink != NOT_HOST || dstLink != NOT_HOST) {
124 + endToEndPaths.add(edgeToEdgePath(srcLink, dstLink));
125 + }
126 + return endToEndPaths;
127 + }
128 +
129 + // Produces a direct edge-to-edge path.
130 + private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink) {
131 + List<Link> links = Lists.newArrayListWithCapacity(2);
132 + // Add source and destination edge links only if they are real.
133 + if (srcLink != NOT_HOST) {
134 + links.add(srcLink);
135 + }
136 + if (dstLink != NOT_HOST) {
137 + links.add(dstLink);
138 + }
139 + return new DefaultPath(PID, links, 2);
140 + }
141 +
142 + // Produces a set of edge-to-edge paths using the set of infrastructure
143 + // paths and the given edge links.
144 + private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink, Set<Path> paths) {
145 + Set<Path> endToEndPaths = Sets.newHashSetWithExpectedSize(paths.size());
146 + for (Path path : paths) {
147 + endToEndPaths.add(edgeToEdgePath(srcLink, dstLink, path));
148 + }
149 + return endToEndPaths;
150 + }
151 +
152 + // Produces an edge-to-edge path using the specified infrastructure path
153 + // and edge links.
154 + private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink, Path path) {
155 + List<Link> links = Lists.newArrayListWithCapacity(path.links().size() + 2);
156 + links.add(srcLink);
157 + links.addAll(path.links());
158 + links.add(dstLink);
159 + return new DefaultPath(path.providerId(), links, path.cost() + 2);
160 + }
161 +
162 + // Special value for edge link to represent that this is really not an
163 + // edge link since the src or dst are really an infrastructure device.
164 + private static class NotHost extends DefaultEdgeLink implements EdgeLink {
165 + NotHost() {
166 + super(PID, new ConnectPoint(HostId.hostId("nic:none"), P0),
167 + new HostLocation(deviceId("none:none"), P0, 0L), false);
168 + }
169 + }
170 +}
1 +package org.onlab.onos.of.controller;
2 +
3 +import org.projectfloodlight.openflow.protocol.OFMessage;
4 +
5 +/**
6 + * Test adapter for the OpenFlow controller interface.
7 + */
8 +public class OpenflowControllerAdapter implements OpenFlowController {
9 + @Override
10 + public Iterable<OpenFlowSwitch> getSwitches() {
11 + return null;
12 + }
13 +
14 + @Override
15 + public Iterable<OpenFlowSwitch> getMasterSwitches() {
16 + return null;
17 + }
18 +
19 + @Override
20 + public Iterable<OpenFlowSwitch> getEqualSwitches() {
21 + return null;
22 + }
23 +
24 + @Override
25 + public OpenFlowSwitch getSwitch(Dpid dpid) {
26 + return null;
27 + }
28 +
29 + @Override
30 + public OpenFlowSwitch getMasterSwitch(Dpid dpid) {
31 + return null;
32 + }
33 +
34 + @Override
35 + public OpenFlowSwitch getEqualSwitch(Dpid dpid) {
36 + return null;
37 + }
38 +
39 + @Override
40 + public void addListener(OpenFlowSwitchListener listener) {
41 + }
42 +
43 + @Override
44 + public void removeListener(OpenFlowSwitchListener listener) {
45 + }
46 +
47 + @Override
48 + public void addPacketListener(int priority, PacketListener listener) {
49 + }
50 +
51 + @Override
52 + public void removePacketListener(PacketListener listener) {
53 + }
54 +
55 + @Override
56 + public void write(Dpid dpid, OFMessage msg) {
57 + }
58 +
59 + @Override
60 + public void processPacket(Dpid dpid, OFMessage msg) {
61 + }
62 +
63 + @Override
64 + public void setRole(Dpid dpid, RoleState role) {
65 + }
66 +}
...@@ -144,10 +144,24 @@ ...@@ -144,10 +144,24 @@
144 </dependency> 144 </dependency>
145 <dependency> 145 <dependency>
146 <groupId>org.onlab.onos</groupId> 146 <groupId>org.onlab.onos</groupId>
147 - <artifactId>onos-of-api</artifactId> 147 + <artifactId>onos-api</artifactId>
148 <version>${project.version}</version> 148 <version>${project.version}</version>
149 + <classifier>tests</classifier>
150 + <scope>test</scope>
149 </dependency> 151 </dependency>
150 152
153 + <dependency>
154 + <groupId>org.onlab.onos</groupId>
155 + <artifactId>onos-of-api</artifactId>
156 + <version>${project.version}</version>
157 + </dependency>
158 + <dependency>
159 + <groupId>org.onlab.onos</groupId>
160 + <artifactId>onos-of-api</artifactId>
161 + <version>${project.version}</version>
162 + <classifier>tests</classifier>
163 + <scope>test</scope>
164 + </dependency>
151 </dependencies> 165 </dependencies>
152 </dependencyManagement> 166 </dependencyManagement>
153 167
......
1 package org.onlab.onos.provider.of.host.impl; 1 package org.onlab.onos.provider.of.host.impl;
2 2
3 -import static org.junit.Assert.assertEquals;
4 -import static org.junit.Assert.assertNotNull;
5 -import static org.junit.Assert.assertNull;
6 -
7 -import java.util.Set;
8 -
9 import org.junit.After; 3 import org.junit.After;
10 import org.junit.Before; 4 import org.junit.Before;
11 import org.junit.Test; 5 import org.junit.Test;
12 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
13 -import org.onlab.onos.net.DeviceId;
14 import org.onlab.onos.net.HostId; 7 import org.onlab.onos.net.HostId;
15 -import org.onlab.onos.net.Link;
16 -import org.onlab.onos.net.Path;
17 import org.onlab.onos.net.host.HostDescription; 8 import org.onlab.onos.net.host.HostDescription;
18 import org.onlab.onos.net.host.HostProvider; 9 import org.onlab.onos.net.host.HostProvider;
19 import org.onlab.onos.net.host.HostProviderRegistry; 10 import org.onlab.onos.net.host.HostProviderRegistry;
20 import org.onlab.onos.net.host.HostProviderService; 11 import org.onlab.onos.net.host.HostProviderService;
21 import org.onlab.onos.net.provider.AbstractProviderService; 12 import org.onlab.onos.net.provider.AbstractProviderService;
22 import org.onlab.onos.net.provider.ProviderId; 13 import org.onlab.onos.net.provider.ProviderId;
23 -import org.onlab.onos.net.topology.ClusterId;
24 -import org.onlab.onos.net.topology.LinkWeight;
25 import org.onlab.onos.net.topology.Topology; 14 import org.onlab.onos.net.topology.Topology;
26 -import org.onlab.onos.net.topology.TopologyCluster; 15 +import org.onlab.onos.net.topology.TopologyServiceAdapter;
27 -import org.onlab.onos.net.topology.TopologyGraph;
28 -import org.onlab.onos.net.topology.TopologyListener;
29 -import org.onlab.onos.net.topology.TopologyService;
30 import org.onlab.onos.of.controller.Dpid; 16 import org.onlab.onos.of.controller.Dpid;
31 -import org.onlab.onos.of.controller.OpenFlowController;
32 import org.onlab.onos.of.controller.OpenFlowPacketContext; 17 import org.onlab.onos.of.controller.OpenFlowPacketContext;
33 -import org.onlab.onos.of.controller.OpenFlowSwitch; 18 +import org.onlab.onos.of.controller.OpenflowControllerAdapter;
34 -import org.onlab.onos.of.controller.OpenFlowSwitchListener;
35 import org.onlab.onos.of.controller.PacketListener; 19 import org.onlab.onos.of.controller.PacketListener;
36 -import org.onlab.onos.of.controller.RoleState;
37 import org.onlab.packet.ARP; 20 import org.onlab.packet.ARP;
38 import org.onlab.packet.Ethernet; 21 import org.onlab.packet.Ethernet;
39 import org.onlab.packet.MACAddress; 22 import org.onlab.packet.MACAddress;
...@@ -41,6 +24,10 @@ import org.onlab.packet.VLANID; ...@@ -41,6 +24,10 @@ import org.onlab.packet.VLANID;
41 import org.projectfloodlight.openflow.protocol.OFMessage; 24 import org.projectfloodlight.openflow.protocol.OFMessage;
42 import org.projectfloodlight.openflow.types.OFPort; 25 import org.projectfloodlight.openflow.types.OFPort;
43 26
27 +import java.util.Set;
28 +
29 +import static org.junit.Assert.*;
30 +
44 public class OpenFlowHostProviderTest { 31 public class OpenFlowHostProviderTest {
45 32
46 private static final Integer INPORT = 10; 33 private static final Integer INPORT = 10;
...@@ -51,7 +38,7 @@ public class OpenFlowHostProviderTest { ...@@ -51,7 +38,7 @@ public class OpenFlowHostProviderTest {
51 private static final VLANID VLAN = VLANID.vlanId(); 38 private static final VLANID VLAN = VLANID.vlanId();
52 private static final MACAddress MAC = MACAddress.valueOf("00:00:11:00:00:01"); 39 private static final MACAddress MAC = MACAddress.valueOf("00:00:11:00:00:01");
53 private static final MACAddress BCMAC = MACAddress.valueOf("ff:ff:ff:ff:ff:ff"); 40 private static final MACAddress BCMAC = MACAddress.valueOf("ff:ff:ff:ff:ff:ff");
54 - private static byte [] IP = new byte [] { 10,0,0,1 }; 41 + private static final byte[] IP = new byte[]{10, 0, 0, 1};
55 42
56 private OpenFlowHostProvider provider = new OpenFlowHostProvider(); 43 private OpenFlowHostProvider provider = new OpenFlowHostProvider();
57 private TestHostRegistry hostService = new TestHostRegistry(); 44 private TestHostRegistry hostService = new TestHostRegistry();
...@@ -145,148 +132,31 @@ public class OpenFlowHostProviderTest { ...@@ -145,148 +132,31 @@ public class OpenFlowHostProviderTest {
145 132
146 } 133 }
147 134
148 - private class TestController implements OpenFlowController { 135 + private class TestController extends OpenflowControllerAdapter {
149 -
150 PacketListener pktListener; 136 PacketListener pktListener;
151 137
152 @Override 138 @Override
153 - public Iterable<OpenFlowSwitch> getSwitches() {
154 - return null;
155 - }
156 -
157 - @Override
158 - public Iterable<OpenFlowSwitch> getMasterSwitches() {
159 - return null;
160 - }
161 -
162 - @Override
163 - public Iterable<OpenFlowSwitch> getEqualSwitches() {
164 - return null;
165 - }
166 -
167 - @Override
168 - public OpenFlowSwitch getSwitch(Dpid dpid) {
169 - return null;
170 - }
171 -
172 - @Override
173 - public OpenFlowSwitch getMasterSwitch(Dpid dpid) {
174 - return null;
175 - }
176 -
177 - @Override
178 - public OpenFlowSwitch getEqualSwitch(Dpid dpid) {
179 - return null;
180 - }
181 -
182 - @Override
183 - public void addListener(OpenFlowSwitchListener listener) {
184 - }
185 -
186 - @Override
187 - public void removeListener(OpenFlowSwitchListener listener) {
188 - }
189 -
190 - @Override
191 public void addPacketListener(int priority, PacketListener listener) { 139 public void addPacketListener(int priority, PacketListener listener) {
192 pktListener = listener; 140 pktListener = listener;
193 } 141 }
194 142
195 @Override 143 @Override
196 - public void removePacketListener(PacketListener listener) {
197 - }
198 -
199 - @Override
200 - public void write(Dpid dpid, OFMessage msg) {
201 - }
202 -
203 - @Override
204 public void processPacket(Dpid dpid, OFMessage msg) { 144 public void processPacket(Dpid dpid, OFMessage msg) {
205 - OpenFlowPacketContext ctx = 145 + OpenFlowPacketContext ctx = new TestPacketContext(dpid);
206 - new TestPacketContext(dpid);
207 -
208 pktListener.handlePacket(ctx); 146 pktListener.handlePacket(ctx);
209 } 147 }
210 -
211 - @Override
212 - public void setRole(Dpid dpid, RoleState role) {
213 - }
214 } 148 }
215 149
216 - private class TestTopologyService implements TopologyService { 150 + private class TestTopologyService extends TopologyServiceAdapter {
217 -
218 - @Override
219 - public Topology currentTopology() {
220 - return null;
221 - }
222 -
223 - @Override
224 - public boolean isLatest(Topology topology) {
225 - return false;
226 - }
227 -
228 - @Override
229 - public TopologyGraph getGraph(Topology topology) {
230 - return null;
231 - }
232 -
233 - @Override
234 - public Set<TopologyCluster> getClusters(Topology topology) {
235 - return null;
236 - }
237 -
238 - @Override
239 - public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
240 - return null;
241 - }
242 -
243 - @Override
244 - public Set<DeviceId> getClusterDevices(Topology topology,
245 - TopologyCluster cluster) {
246 - return null;
247 - }
248 -
249 - @Override
250 - public Set<Link> getClusterLinks(Topology topology,
251 - TopologyCluster cluster) {
252 - return null;
253 - }
254 -
255 - @Override
256 - public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
257 - return null;
258 - }
259 -
260 - @Override
261 - public Set<Path> getPaths(Topology topology, DeviceId src,
262 - DeviceId dst, LinkWeight weight) {
263 - return null;
264 - }
265 -
266 @Override 151 @Override
267 public boolean isInfrastructure(Topology topology, 152 public boolean isInfrastructure(Topology topology,
268 - ConnectPoint connectPoint) { 153 + ConnectPoint connectPoint) {
269 //simulate DPID3 as an infrastructure switch 154 //simulate DPID3 as an infrastructure switch
270 if (Dpid.dpid(connectPoint.deviceId().uri()).equals(DPID3)) { 155 if (Dpid.dpid(connectPoint.deviceId().uri()).equals(DPID3)) {
271 return true; 156 return true;
272 } 157 }
273 return false; 158 return false;
274 } 159 }
275 -
276 - @Override
277 - public boolean isBroadcastPoint(Topology topology,
278 - ConnectPoint connectPoint) {
279 - return false;
280 - }
281 -
282 - @Override
283 - public void addListener(TopologyListener listener) {
284 - }
285 -
286 - @Override
287 - public void removeListener(TopologyListener listener) {
288 - }
289 -
290 } 160 }
291 161
292 private class TestPacketContext implements OpenFlowPacketContext { 162 private class TestPacketContext implements OpenFlowPacketContext {
...@@ -319,9 +189,9 @@ public class OpenFlowHostProviderTest { ...@@ -319,9 +189,9 @@ public class OpenFlowHostProviderTest {
319 // just things we (and serializers) need 189 // just things we (and serializers) need
320 ARP arp = new ARP(); 190 ARP arp = new ARP();
321 arp.setSenderProtocolAddress(IP) 191 arp.setSenderProtocolAddress(IP)
322 - .setSenderHardwareAddress(MAC.toBytes()) 192 + .setSenderHardwareAddress(MAC.toBytes())
323 - .setTargetHardwareAddress(BCMAC.toBytes()) 193 + .setTargetHardwareAddress(BCMAC.toBytes())
324 - .setTargetProtocolAddress(IP); 194 + .setTargetProtocolAddress(IP);
325 195
326 Ethernet eth = new Ethernet(); 196 Ethernet eth = new Ethernet();
327 eth.setEtherType(Ethernet.TYPE_ARP) 197 eth.setEtherType(Ethernet.TYPE_ARP)
......
...@@ -29,6 +29,19 @@ ...@@ -29,6 +29,19 @@
29 <groupId>org.onlab.onos</groupId> 29 <groupId>org.onlab.onos</groupId>
30 <artifactId>onos-of-api</artifactId> 30 <artifactId>onos-of-api</artifactId>
31 </dependency> 31 </dependency>
32 + <dependency>
33 + <groupId>org.onlab.onos</groupId>
34 + <artifactId>onos-of-api</artifactId>
35 + <classifier>tests</classifier>
36 + <scope>test</scope>
37 + </dependency>
38 +
39 + <dependency>
40 + <groupId>org.onlab.onos</groupId>
41 + <artifactId>onos-api</artifactId>
42 + <classifier>tests</classifier>
43 + <scope>test</scope>
44 + </dependency>
32 </dependencies> 45 </dependencies>
33 46
34 </project> 47 </project>
......