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