Hyunsun Moon | 2c3f0ee | 2017-04-06 16:47:21 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present 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 | package org.opencord.cordvtn.impl; |
| 17 | |
| 18 | import org.onlab.packet.ChassisId; |
| 19 | import org.onlab.packet.Ip4Address; |
| 20 | import org.onlab.packet.TpPort; |
| 21 | import org.onosproject.net.DefaultAnnotations; |
| 22 | import org.onosproject.net.DefaultDevice; |
| 23 | import org.onosproject.net.DefaultPort; |
| 24 | import org.onosproject.net.Device; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.Port; |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.provider.ProviderId; |
| 29 | import org.opencord.cordvtn.api.net.CidrAddr; |
| 30 | import org.opencord.cordvtn.api.node.CordVtnNode; |
| 31 | import org.opencord.cordvtn.api.node.CordVtnNodeState; |
| 32 | import org.opencord.cordvtn.api.node.SshAccessInfo; |
| 33 | |
| 34 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
| 35 | import static org.onosproject.net.Device.Type.SWITCH; |
| 36 | |
| 37 | /** |
| 38 | * Provides a set of test CordVtnNode parameters for use with CordVtnNode related tests. |
| 39 | */ |
| 40 | public abstract class CordVtnNodeTest { |
| 41 | |
| 42 | public static final SshAccessInfo TEST_SSH_INFO = new SshAccessInfo( |
| 43 | Ip4Address.valueOf("192.168.0.1"), |
| 44 | TpPort.tpPort(22), |
| 45 | "root", |
| 46 | "/root/.ssh/id_rsa"); |
| 47 | public static final CidrAddr TEST_CIDR_ADDR = CidrAddr.valueOf("192.168.0.1/24"); |
| 48 | public static final String TEST_DATA_IFACE = "eth0"; |
| 49 | public static final String TEST_VXLAN_IFACE = "vxlan"; |
| 50 | |
| 51 | public static Device createDevice(long devIdNum) { |
| 52 | return new DefaultDevice(new ProviderId("of", "foo"), |
| 53 | DeviceId.deviceId(String.format("of:%016d", devIdNum)), |
| 54 | SWITCH, |
| 55 | "manufacturer", |
| 56 | "hwVersion", |
| 57 | "swVersion", |
| 58 | "serialNumber", |
| 59 | new ChassisId(1)); |
| 60 | } |
| 61 | |
| 62 | public static Port createPort(Device device, long portNumber, String portName) { |
| 63 | return new DefaultPort(device, |
| 64 | PortNumber.portNumber(portNumber), |
| 65 | true, |
| 66 | DefaultAnnotations.builder().set(PORT_NAME, portName).build()); |
| 67 | } |
| 68 | |
| 69 | public static CordVtnNode createNode(String hostname, Device device, CordVtnNodeState state) { |
| 70 | return DefaultCordVtnNode.builder() |
| 71 | .hostname(hostname) |
| 72 | .hostManagementIp(TEST_CIDR_ADDR) |
| 73 | .localManagementIp(TEST_CIDR_ADDR) |
| 74 | .dataIp(TEST_CIDR_ADDR) |
| 75 | .integrationBridgeId(device.id()) |
| 76 | .dataInterface(TEST_DATA_IFACE) |
| 77 | .sshInfo(TEST_SSH_INFO) |
| 78 | .state(state) |
| 79 | .build(); |
| 80 | } |
| 81 | } |