blob: e1e78ed845c552ae773d45c840c38bdb90aa470a [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;
tomca90c462014-09-22 11:40:58 -07005import org.onlab.packet.IpPrefix;
6
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),
48 new HashSet<IpPrefix>());
49 }
50
51 // Short-hand for creating a link.
52 public static Link link(String src, int sp, String dst, int dp) {
53 return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)),
54 new ConnectPoint(did(dst), portNumber(dp)),
55 Link.Type.DIRECT);
56 }
57
58 // Creates a path that leads through the given devices.
59 public static Path createPath(String... ids) {
60 List<Link> links = new ArrayList<>();
61 for (int i = 0; i < ids.length - 1; i++) {
62 links.add(link(ids[i], i, ids[i + 1], i));
63 }
64 return new DefaultPath(PID, links, ids.length);
65 }
66
67}