Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 | |
| 17 | package org.onosproject.provider.nil; |
| 18 | |
| 19 | import com.google.common.collect.Maps; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onlab.packet.VlanId; |
| 22 | import org.onosproject.net.Device; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.HostId; |
| 25 | |
| 26 | import java.util.Map; |
| 27 | |
| 28 | import static org.onlab.util.Tools.toHex; |
| 29 | import static org.onosproject.provider.nil.NullProviders.SCHEME; |
| 30 | |
| 31 | /** |
| 32 | * Custom topology defined by a concise language. |
| 33 | */ |
| 34 | public class CustomTopologySimulator extends TopologySimulator { |
| 35 | |
| 36 | private int nextDeviceId = 0; |
| 37 | private int nextHostId = 0; |
| 38 | |
| 39 | private Map<String, DeviceId> nameToId = Maps.newConcurrentMap(); |
| 40 | |
| 41 | /** |
| 42 | * Returns the next device id. |
| 43 | * |
| 44 | * @return the next device id |
| 45 | */ |
| 46 | public DeviceId nextDeviceId() { |
| 47 | return DeviceId.deviceId(SCHEME + ":" + toHex(++nextDeviceId)); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the next host id. |
| 52 | * |
| 53 | * @return the next host id |
| 54 | */ |
| 55 | public HostId nextHostId() { |
| 56 | return HostId.hostId(MacAddress.valueOf(nextHostId), VlanId.NONE); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the identifier of the device with the specified alias. |
| 61 | * |
| 62 | * @param name device name |
| 63 | * @return device identifier |
| 64 | */ |
| 65 | public DeviceId deviceId(String name) { |
| 66 | return nameToId.get(name); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Creates simulated device. |
| 71 | * |
| 72 | * @param id device identifier |
| 73 | * @param name device name |
| 74 | * @param type device type |
| 75 | * @param portCount number of device ports |
| 76 | */ |
| 77 | public void createDevice(DeviceId id, String name, Device.Type type, int portCount) { |
| 78 | int chassisId = Integer.parseInt(id.uri().getSchemeSpecificPart()); |
| 79 | createDevice(id, chassisId, type, portCount); |
| 80 | nameToId.put(name, id); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | protected void createDevices() { |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | protected void createLinks() { |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | protected void createHosts() { |
| 93 | } |
| 94 | } |