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 | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 82 | * model of the topo2CurrentRegion device props from Device below |
| 83 | */ |
| 84 | export interface DeviceProps { |
| 85 | latitude: number; |
| 86 | longitude: number; |
| 87 | name: string; |
| 88 | locType: LocationType; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * model of the topo2CurrentRegion Loc part of the MetaUi below |
| 93 | */ |
| 94 | export interface LocMeta { |
| 95 | lng: number; |
| 96 | lat: number; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * model of the topo2CurrentRegion MetaUi from Device below |
| 101 | */ |
| 102 | export interface MetaUi { |
| 103 | equivLoc: LocMeta; |
| 104 | x: number; |
| 105 | y: number; |
| 106 | } |
| 107 | |
| 108 | export interface HostProps { |
| 109 | gridX: number; |
| 110 | gridY: number; |
| 111 | latitude: number; |
| 112 | longitude: number; |
| 113 | locType: LocationType; |
| 114 | name: string; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Implementing SimulationNodeDatum interface into our custom Node class |
| 119 | */ |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 120 | export abstract class Node implements UiElement, d3.SimulationNodeDatum { |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 121 | // Optional - defining optional implementation properties - required for relevant typing assistance |
| 122 | index?: number; |
| 123 | x: number; |
| 124 | y: number; |
| 125 | vx?: number; |
| 126 | vy?: number; |
| 127 | fx?: number | null; |
| 128 | fy?: number | null; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 129 | nodeType: NodeType; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 130 | id: string; |
| 131 | |
| 132 | protected constructor(id) { |
| 133 | this.id = id; |
| 134 | this.x = 0; |
| 135 | this.y = 0; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * model of the topo2CurrentRegion device from Region below |
| 141 | */ |
| 142 | export class Device extends Node { |
| 143 | id: string; |
| 144 | layer: LayerType; |
| 145 | location: LocationType; |
| 146 | metaUi: MetaUi; |
| 147 | master: string; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 148 | online: boolean; |
| 149 | props: DeviceProps; |
| 150 | type: string; |
| 151 | |
| 152 | constructor(id: string) { |
| 153 | super(id); |
| 154 | } |
| 155 | } |
| 156 | |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 157 | /** |
| 158 | * Model of the ONOS Host element in the topology |
| 159 | */ |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 160 | export class Host extends Node { |
| 161 | configured: boolean; |
| 162 | id: string; |
| 163 | ips: string[]; |
| 164 | layer: LayerType; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 165 | props: HostProps; |
| 166 | |
| 167 | constructor(id: string) { |
| 168 | super(id); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
| 173 | /** |
| 174 | * model of the topo2CurrentRegion subregion from Region below |
| 175 | */ |
| 176 | export class SubRegion extends Node { |
| 177 | id: string; |
| 178 | location: Location; |
| 179 | nDevs: number; |
| 180 | nHosts: number; |
| 181 | name: string; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 182 | props: RegionProps; |
| 183 | |
| 184 | constructor(id: string) { |
| 185 | super(id); |
| 186 | } |
| 187 | } |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Enumerated values for topology update event types |
| 191 | */ |
| 192 | export enum ModelEventType { |
| 193 | HOST_ADDED_OR_UPDATED, |
| 194 | LINK_ADDED_OR_UPDATED, |
| 195 | DEVICE_ADDED_OR_UPDATED, |
| 196 | DEVICE_REMOVED, |
| 197 | HOST_REMOVED |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Enumerated values for topology update event memo field |
| 202 | */ |
| 203 | export enum ModelEventMemo { |
| 204 | ADDED = 'added', |
| 205 | REMOVED = 'removed', |
| 206 | UPDATED = 'updated' |
| 207 | } |
| 208 | |