blob: 1d2e1af4ec3843dece14b7945d27ad5a5c7450db [file] [log] [blame]
tomca90c462014-09-22 11:40:58 -07001package org.onlab.onos.net;
2
3import org.onlab.onos.net.provider.ProviderId;
alshabib7911a052014-10-16 17:49:37 -07004import org.onlab.packet.ChassisId;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -07005import org.onlab.packet.IpAddress;
tomca90c462014-09-22 11:40:58 -07006
7import java.util.ArrayList;
8import java.util.HashSet;
9import java.util.List;
10
11import static org.onlab.onos.net.DeviceId.deviceId;
12import static org.onlab.onos.net.HostId.hostId;
13import static org.onlab.onos.net.PortNumber.portNumber;
14import static org.onlab.packet.MacAddress.valueOf;
15import static org.onlab.packet.VlanId.vlanId;
16
17/**
18 * Miscellaneous tools for testing core related to the network model.
19 */
20public final class NetTestTools {
21
22 private NetTestTools() {
23 }
24
25 public static final ProviderId PID = new ProviderId("of", "foo");
26
27 // Short-hand for producing a device id from a string
28 public static DeviceId did(String id) {
29 return deviceId("of:" + id);
30 }
31
32
33 // Short-hand for producing a host id from a string
34 public static HostId hid(String id) {
tom545708e2014-10-09 17:10:02 -070035 return hostId(id);
tomca90c462014-09-22 11:40:58 -070036 }
37
38 // Crates a new device with the specified id
39 public static Device device(String id) {
40 return new DefaultDevice(PID, did(id), Device.Type.SWITCH,
alshabib7911a052014-10-16 17:49:37 -070041 "mfg", "1.0", "1.1", "1234", new ChassisId());
tomca90c462014-09-22 11:40:58 -070042 }
43
44 // Crates a new host with the specified id
45 public static Host host(String id, String did) {
46 return new DefaultHost(PID, hid(id), valueOf(1234), vlanId((short) 2),
47 new HostLocation(did(did), portNumber(1), 321),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070048 new HashSet<IpAddress>());
tomca90c462014-09-22 11:40:58 -070049 }
50
Ray Milkeye6684082014-10-16 16:59:47 -070051 // Short-hand for creating a connection point.
52 public static ConnectPoint connectPoint(String id, int port) {
53 return new ConnectPoint(did(id), portNumber(port));
54 }
55
tomca90c462014-09-22 11:40:58 -070056 // Short-hand for creating a link.
57 public static Link link(String src, int sp, String dst, int dp) {
Ray Milkeye6684082014-10-16 16:59:47 -070058 return new DefaultLink(PID,
59 connectPoint(src, sp),
60 connectPoint(dst, dp),
tomca90c462014-09-22 11:40:58 -070061 Link.Type.DIRECT);
62 }
63
64 // Creates a path that leads through the given devices.
65 public static Path createPath(String... ids) {
66 List<Link> links = new ArrayList<>();
67 for (int i = 0; i < ids.length - 1; i++) {
68 links.add(link(ids[i], i, ids[i + 1], i));
69 }
70 return new DefaultPath(PID, links, ids.length);
71 }
72
73}