Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 1 | /* |
| 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 | import * as d3 from 'd3'; |
| 17 | import {LocationType} from '../../backgroundsvg/backgroundsvg.component'; |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 18 | import {LayerType, Location, NodeType, RegionProps} from './regions'; |
Sean Condon | ee5d4b9 | 2019-03-11 19:57:34 +0000 | [diff] [blame] | 19 | import {MetaUi} from 'gui2-fw-lib'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 20 | |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 21 | export interface UiElement { |
| 22 | index?: number; |
| 23 | id: string; |
| 24 | } |
| 25 | |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 26 | export namespace LabelToggle { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame^] | 27 | /** |
| 28 | * Toggle state for how device labels should be displayed |
| 29 | */ |
| 30 | export enum Enum { |
| 31 | NONE, |
| 32 | ID, |
| 33 | NAME |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Add the method 'next()' to the LabelToggle enum above |
| 38 | */ |
| 39 | export function next(current: Enum) { |
| 40 | if (current === Enum.NONE) { |
| 41 | return Enum.ID; |
| 42 | } else if (current === Enum.ID) { |
| 43 | return Enum.NAME; |
| 44 | } else if (current === Enum.NAME) { |
| 45 | return Enum.NONE; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 50 | export namespace HostLabelToggle { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame^] | 51 | /** |
| 52 | * Toggle state for how host labels should be displayed |
| 53 | */ |
| 54 | export enum Enum { |
| 55 | NONE, |
| 56 | NAME, |
| 57 | IP, |
| 58 | MAC |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Add the method 'next()' to the HostLabelToggle enum above |
| 63 | */ |
| 64 | export function next(current: Enum) { |
| 65 | if (current === Enum.NONE) { |
| 66 | return Enum.NAME; |
| 67 | } else if (current === Enum.NAME) { |
| 68 | return Enum.IP; |
| 69 | } else if (current === Enum.IP) { |
| 70 | return Enum.MAC; |
| 71 | } else if (current === Enum.MAC) { |
| 72 | return Enum.NONE; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 77 | export namespace GridDisplayToggle { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame^] | 78 | /** |
| 79 | * Toggle state for how the grid should be displayed |
| 80 | */ |
| 81 | export enum Enum { |
| 82 | GRIDNONE, |
| 83 | GRID1000, |
| 84 | GRIDGEO, |
| 85 | GRIDBOTH |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Add the method 'next()' to the GridDisplayToggle enum above |
| 90 | */ |
| 91 | export function next(current: Enum) { |
| 92 | if (current === Enum.GRIDNONE) { |
| 93 | return Enum.GRID1000; |
| 94 | } else if (current === Enum.GRID1000) { |
| 95 | return Enum.GRIDGEO; |
| 96 | } else if (current === Enum.GRIDGEO) { |
| 97 | return Enum.GRIDBOTH; |
| 98 | } else if (current === Enum.GRIDBOTH) { |
| 99 | return Enum.GRIDNONE; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 105 | * model of the topo2CurrentRegion device props from Device below |
| 106 | */ |
| 107 | export interface DeviceProps { |
| 108 | latitude: number; |
| 109 | longitude: number; |
| 110 | name: string; |
| 111 | locType: LocationType; |
Sean Condon | 59d3137 | 2019-02-02 20:07:00 +0000 | [diff] [blame] | 112 | uiType: string; |
Sean Condon | ee54576 | 2019-03-09 10:43:58 +0000 | [diff] [blame] | 113 | channelId: string; |
| 114 | managementAddress: string; |
| 115 | protocol: string; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 118 | export interface HostProps { |
| 119 | gridX: number; |
| 120 | gridY: number; |
| 121 | latitude: number; |
| 122 | longitude: number; |
| 123 | locType: LocationType; |
| 124 | name: string; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Implementing SimulationNodeDatum interface into our custom Node class |
| 129 | */ |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 130 | export abstract class Node implements UiElement, d3.SimulationNodeDatum { |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 131 | // Optional - defining optional implementation properties - required for relevant typing assistance |
| 132 | index?: number; |
| 133 | x: number; |
| 134 | y: number; |
| 135 | vx?: number; |
| 136 | vy?: number; |
| 137 | fx?: number | null; |
| 138 | fy?: number | null; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 139 | nodeType: NodeType; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 140 | id: string; |
| 141 | |
| 142 | protected constructor(id) { |
| 143 | this.id = id; |
| 144 | this.x = 0; |
| 145 | this.y = 0; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * model of the topo2CurrentRegion device from Region below |
| 151 | */ |
| 152 | export class Device extends Node { |
| 153 | id: string; |
| 154 | layer: LayerType; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 155 | location: Location; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 156 | metaUi: MetaUi; |
| 157 | master: string; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 158 | online: boolean; |
| 159 | props: DeviceProps; |
| 160 | type: string; |
| 161 | |
| 162 | constructor(id: string) { |
| 163 | super(id); |
| 164 | } |
| 165 | } |
| 166 | |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 167 | /** |
| 168 | * Model of the ONOS Host element in the topology |
| 169 | */ |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 170 | export class Host extends Node { |
| 171 | configured: boolean; |
| 172 | id: string; |
| 173 | ips: string[]; |
| 174 | layer: LayerType; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 175 | props: HostProps; |
| 176 | |
| 177 | constructor(id: string) { |
| 178 | super(id); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | |
| 183 | /** |
| 184 | * model of the topo2CurrentRegion subregion from Region below |
| 185 | */ |
| 186 | export class SubRegion extends Node { |
| 187 | id: string; |
| 188 | location: Location; |
| 189 | nDevs: number; |
| 190 | nHosts: number; |
| 191 | name: string; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 192 | props: RegionProps; |
| 193 | |
| 194 | constructor(id: string) { |
| 195 | super(id); |
| 196 | } |
| 197 | } |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * Enumerated values for topology update event types |
| 201 | */ |
| 202 | export enum ModelEventType { |
| 203 | HOST_ADDED_OR_UPDATED, |
| 204 | LINK_ADDED_OR_UPDATED, |
| 205 | DEVICE_ADDED_OR_UPDATED, |
| 206 | DEVICE_REMOVED, |
| 207 | HOST_REMOVED |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Enumerated values for topology update event memo field |
| 212 | */ |
| 213 | export enum ModelEventMemo { |
| 214 | ADDED = 'added', |
| 215 | REMOVED = 'removed', |
| 216 | UPDATED = 'updated' |
| 217 | } |
| 218 | |