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 | |
| 25 | /** |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 26 | * Toggle state for how device labels should be displayed |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 27 | */ |
| 28 | export enum LabelToggle { |
| 29 | NONE, |
| 30 | ID, |
| 31 | NAME |
| 32 | } |
| 33 | |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Add the method 'next()' to the LabelToggle enum above |
| 36 | */ |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 37 | export namespace LabelToggle { |
| 38 | export function next(current: LabelToggle) { |
| 39 | if (current === LabelToggle.NONE) { |
| 40 | return LabelToggle.ID; |
| 41 | } else if (current === LabelToggle.ID) { |
| 42 | return LabelToggle.NAME; |
| 43 | } else if (current === LabelToggle.NAME) { |
| 44 | return LabelToggle.NONE; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 50 | * Toggle state for how host labels should be displayed |
| 51 | */ |
| 52 | export enum HostLabelToggle { |
| 53 | NONE, |
| 54 | NAME, |
| 55 | IP, |
| 56 | MAC |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Add the method 'next()' to the HostLabelToggle enum above |
| 61 | */ |
| 62 | export namespace HostLabelToggle { |
| 63 | export function next(current: HostLabelToggle) { |
| 64 | if (current === HostLabelToggle.NONE) { |
| 65 | return HostLabelToggle.NAME; |
| 66 | } else if (current === HostLabelToggle.NAME) { |
| 67 | return HostLabelToggle.IP; |
| 68 | } else if (current === HostLabelToggle.IP) { |
| 69 | return HostLabelToggle.MAC; |
| 70 | } else if (current === HostLabelToggle.MAC) { |
| 71 | return HostLabelToggle.NONE; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 77 | * model of the topo2CurrentRegion device props from Device below |
| 78 | */ |
| 79 | export interface DeviceProps { |
| 80 | latitude: number; |
| 81 | longitude: number; |
| 82 | name: string; |
| 83 | locType: LocationType; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * model of the topo2CurrentRegion Loc part of the MetaUi below |
| 88 | */ |
| 89 | export interface LocMeta { |
| 90 | lng: number; |
| 91 | lat: number; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * model of the topo2CurrentRegion MetaUi from Device below |
| 96 | */ |
| 97 | export interface MetaUi { |
| 98 | equivLoc: LocMeta; |
| 99 | x: number; |
| 100 | y: number; |
| 101 | } |
| 102 | |
| 103 | export interface HostProps { |
| 104 | gridX: number; |
| 105 | gridY: number; |
| 106 | latitude: number; |
| 107 | longitude: number; |
| 108 | locType: LocationType; |
| 109 | name: string; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Implementing SimulationNodeDatum interface into our custom Node class |
| 114 | */ |
| 115 | export abstract class Node implements d3.SimulationNodeDatum { |
| 116 | // Optional - defining optional implementation properties - required for relevant typing assistance |
| 117 | index?: number; |
| 118 | x: number; |
| 119 | y: number; |
| 120 | vx?: number; |
| 121 | vy?: number; |
| 122 | fx?: number | null; |
| 123 | fy?: number | null; |
| 124 | |
| 125 | id: string; |
| 126 | |
| 127 | protected constructor(id) { |
| 128 | this.id = id; |
| 129 | this.x = 0; |
| 130 | this.y = 0; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * model of the topo2CurrentRegion device from Region below |
| 136 | */ |
| 137 | export class Device extends Node { |
| 138 | id: string; |
| 139 | layer: LayerType; |
| 140 | location: LocationType; |
| 141 | metaUi: MetaUi; |
| 142 | master: string; |
| 143 | nodeType: NodeType; |
| 144 | online: boolean; |
| 145 | props: DeviceProps; |
| 146 | type: string; |
| 147 | |
| 148 | constructor(id: string) { |
| 149 | super(id); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | export class Host extends Node { |
| 154 | configured: boolean; |
| 155 | id: string; |
| 156 | ips: string[]; |
| 157 | layer: LayerType; |
| 158 | nodeType: NodeType; |
| 159 | props: HostProps; |
| 160 | |
| 161 | constructor(id: string) { |
| 162 | super(id); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /** |
| 168 | * model of the topo2CurrentRegion subregion from Region below |
| 169 | */ |
| 170 | export class SubRegion extends Node { |
| 171 | id: string; |
| 172 | location: Location; |
| 173 | nDevs: number; |
| 174 | nHosts: number; |
| 175 | name: string; |
| 176 | nodeType: NodeType; |
| 177 | props: RegionProps; |
| 178 | |
| 179 | constructor(id: string) { |
| 180 | super(id); |
| 181 | } |
| 182 | } |