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