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