blob: 0495038c8c9bb5075e6c9d18a2354cb5c672eb52 [file] [log] [blame]
Thomas Vachuskaa8e74772018-02-26 11:33:35 -08001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.provider.nil.cli;
18
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onlab.packet.IpAddress;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.HostId;
24import org.onosproject.net.HostLocation;
25import org.onosproject.provider.nil.CustomTopologySimulator;
26import org.onosproject.provider.nil.NullProviders;
27import org.onosproject.provider.nil.TopologySimulator;
28
29import java.util.List;
30
31/**
32 * Adds a simulated end-station host to the custom topology simulation.
33 */
34@Command(scope = "onos", name = "null-create-hosts",
35 description = "Adds a simulated end-station host to the custom topology simulation")
36public class CreateNullHosts extends CreateNullEntity {
37
38 @Argument(index = 0, name = "deviceName", description = "Name of device where hosts are attached",
39 required = true)
40 String deviceName = null;
41
42 @Argument(index = 1, name = "hostIpPattern", description = "Host IP pattern",
43 required = true)
44 String hostIpPattern = null;
45
46 @Argument(index = 2, name = "hostCount", description = "Number of hosts to create",
47 required = true)
48 int hostCount = 0;
49
50 @Override
51 protected void execute() {
52 NullProviders service = get(NullProviders.class);
53
54 TopologySimulator simulator = service.currentSimulator();
55 if (!validateSimulator(simulator)) {
56 return;
57 }
58
59 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
60
61 List<ConnectPoint> points = findAvailablePorts(sim.deviceId(deviceName));
62 String pattern = hostIpPattern.replace("*", "%d");
63 for (int h = 0; h < hostCount; h++) {
64 HostLocation location = new HostLocation(points.get(h), System.currentTimeMillis());
65 IpAddress ip = IpAddress.valueOf(String.format(pattern, h));
66 HostId id = sim.nextHostId();
67 sim.createHost(id, location, ip);
68 }
69 }
70
71}