blob: af280a43d7a7a807bad2be86fcb5c18c4a388fa5 [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 Condonee545762019-03-09 10:43:58 +0000114 channelId: string;
115 managementAddress: string;
116 protocol: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000117}
118
Sean Condon0c577f62018-11-18 22:40:05 +0000119export 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 Condon50855cf2018-12-23 15:37:42 +0000131export abstract class Node implements UiElement, d3.SimulationNodeDatum {
Sean Condon0c577f62018-11-18 22:40:05 +0000132 // 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 Condon50855cf2018-12-23 15:37:42 +0000140 nodeType: NodeType;
Sean Condon0c577f62018-11-18 22:40:05 +0000141 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 */
153export class Device extends Node {
154 id: string;
155 layer: LayerType;
Sean Condon71910542019-02-16 18:16:42 +0000156 location: Location;
Sean Condon0c577f62018-11-18 22:40:05 +0000157 metaUi: MetaUi;
158 master: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000159 online: boolean;
160 props: DeviceProps;
161 type: string;
162
163 constructor(id: string) {
164 super(id);
165 }
166}
167
Sean Condon50855cf2018-12-23 15:37:42 +0000168/**
169 * Model of the ONOS Host element in the topology
170 */
Sean Condon0c577f62018-11-18 22:40:05 +0000171export class Host extends Node {
172 configured: boolean;
173 id: string;
174 ips: string[];
175 layer: LayerType;
Sean Condon0c577f62018-11-18 22:40:05 +0000176 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 */
187export class SubRegion extends Node {
188 id: string;
189 location: Location;
190 nDevs: number;
191 nHosts: number;
192 name: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000193 props: RegionProps;
194
195 constructor(id: string) {
196 super(id);
197 }
198}
Sean Condon50855cf2018-12-23 15:37:42 +0000199
200/**
201 * Enumerated values for topology update event types
202 */
203export 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 */
214export enum ModelEventMemo {
215 ADDED = 'added',
216 REMOVED = 'removed',
217 UPDATED = 'updated'
218}
219