blob: ce5441ff93168320bf0a213d817bd1c151397c61 [file] [log] [blame]
Sean Condon0c577f62018-11-18 22:40:05 +00001/*
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 */
16import * as d3 from 'd3';
17import {LocationType} from '../../backgroundsvg/backgroundsvg.component';
Sean Condon1ae15802019-03-02 09:07:18 +000018import {LayerType, Location, NodeType, RegionProps} from './regions';
19import {LocMeta, LogService, MetaUi} from 'gui2-fw-lib';
20import {ZoomUtils} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000021
Sean Condon50855cf2018-12-23 15:37:42 +000022export interface UiElement {
23 index?: number;
24 id: string;
25}
26
Sean Condon0c577f62018-11-18 22:40:05 +000027/**
Sean Condon021f0fa2018-12-06 23:31:11 -080028 * Toggle state for how device labels should be displayed
Sean Condon0c577f62018-11-18 22:40:05 +000029 */
30export enum LabelToggle {
31 NONE,
32 ID,
33 NAME
34}
35
Sean Condon021f0fa2018-12-06 23:31:11 -080036/**
37 * Add the method 'next()' to the LabelToggle enum above
38 */
Sean Condon0c577f62018-11-18 22:40:05 +000039export 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 Condon021f0fa2018-12-06 23:31:11 -080052 * Toggle state for how host labels should be displayed
53 */
54export enum HostLabelToggle {
55 NONE,
56 NAME,
57 IP,
58 MAC
59}
60
61/**
62 * Add the method 'next()' to the HostLabelToggle enum above
63 */
64export 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 Condon71910542019-02-16 18:16:42 +000079 * Toggle state for how the grid should be displayed
80 */
81export enum GridDisplayToggle {
82 GRIDNONE,
83 GRID1000,
84 GRIDGEO,
85 GRIDBOTH
86}
87
88/**
89 * Add the method 'next()' to the GridDisplayToggle enum above
90 */
91export 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 Condon0c577f62018-11-18 22:40:05 +0000106 * model of the topo2CurrentRegion device props from Device below
107 */
108export interface DeviceProps {
109 latitude: number;
110 longitude: number;
111 name: string;
112 locType: LocationType;
Sean Condon59d31372019-02-02 20:07:00 +0000113 uiType: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000114}
115
Sean Condon0c577f62018-11-18 22:40:05 +0000116export interface HostProps {
117 gridX: number;
118 gridY: number;
119 latitude: number;
120 longitude: number;
121 locType: LocationType;
122 name: string;
123}
124
125/**
126 * Implementing SimulationNodeDatum interface into our custom Node class
127 */
Sean Condon50855cf2018-12-23 15:37:42 +0000128export abstract class Node implements UiElement, d3.SimulationNodeDatum {
Sean Condon0c577f62018-11-18 22:40:05 +0000129 // Optional - defining optional implementation properties - required for relevant typing assistance
130 index?: number;
131 x: number;
132 y: number;
133 vx?: number;
134 vy?: number;
135 fx?: number | null;
136 fy?: number | null;
Sean Condon50855cf2018-12-23 15:37:42 +0000137 nodeType: NodeType;
Sean Condon0c577f62018-11-18 22:40:05 +0000138 id: string;
139
140 protected constructor(id) {
141 this.id = id;
142 this.x = 0;
143 this.y = 0;
144 }
145}
146
147/**
148 * model of the topo2CurrentRegion device from Region below
149 */
150export class Device extends Node {
151 id: string;
152 layer: LayerType;
Sean Condon71910542019-02-16 18:16:42 +0000153 location: Location;
Sean Condon0c577f62018-11-18 22:40:05 +0000154 metaUi: MetaUi;
155 master: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000156 online: boolean;
157 props: DeviceProps;
158 type: string;
159
160 constructor(id: string) {
161 super(id);
162 }
163}
164
Sean Condon50855cf2018-12-23 15:37:42 +0000165/**
166 * Model of the ONOS Host element in the topology
167 */
Sean Condon0c577f62018-11-18 22:40:05 +0000168export class Host extends Node {
169 configured: boolean;
170 id: string;
171 ips: string[];
172 layer: LayerType;
Sean Condon0c577f62018-11-18 22:40:05 +0000173 props: HostProps;
174
175 constructor(id: string) {
176 super(id);
177 }
178}
179
180
181/**
182 * model of the topo2CurrentRegion subregion from Region below
183 */
184export class SubRegion extends Node {
185 id: string;
186 location: Location;
187 nDevs: number;
188 nHosts: number;
189 name: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000190 props: RegionProps;
191
192 constructor(id: string) {
193 super(id);
194 }
195}
Sean Condon50855cf2018-12-23 15:37:42 +0000196
197/**
198 * Enumerated values for topology update event types
199 */
200export enum ModelEventType {
201 HOST_ADDED_OR_UPDATED,
202 LINK_ADDED_OR_UPDATED,
203 DEVICE_ADDED_OR_UPDATED,
204 DEVICE_REMOVED,
205 HOST_REMOVED
206}
207
208/**
209 * Enumerated values for topology update event memo field
210 */
211export enum ModelEventMemo {
212 ADDED = 'added',
213 REMOVED = 'removed',
214 UPDATED = 'updated'
215}
216