blob: 5f8d8c69d15d23ffc62de059a92b5b514add577a [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';
18import {
19 LayerType,
20 Location,
21 NodeType,
22 RegionProps
23} from './regions';
24
Sean Condon50855cf2018-12-23 15:37:42 +000025export interface UiElement {
26 index?: number;
27 id: string;
28}
29
Sean Condon0c577f62018-11-18 22:40:05 +000030/**
Sean Condon021f0fa2018-12-06 23:31:11 -080031 * Toggle state for how device labels should be displayed
Sean Condon0c577f62018-11-18 22:40:05 +000032 */
33export enum LabelToggle {
34 NONE,
35 ID,
36 NAME
37}
38
Sean Condon021f0fa2018-12-06 23:31:11 -080039/**
40 * Add the method 'next()' to the LabelToggle enum above
41 */
Sean Condon0c577f62018-11-18 22:40:05 +000042export 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 Condon021f0fa2018-12-06 23:31:11 -080055 * Toggle state for how host labels should be displayed
56 */
57export enum HostLabelToggle {
58 NONE,
59 NAME,
60 IP,
61 MAC
62}
63
64/**
65 * Add the method 'next()' to the HostLabelToggle enum above
66 */
67export 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 Condon71910542019-02-16 18:16:42 +000082 * Toggle state for how the grid should be displayed
83 */
84export enum GridDisplayToggle {
85 GRIDNONE,
86 GRID1000,
87 GRIDGEO,
88 GRIDBOTH
89}
90
91/**
92 * Add the method 'next()' to the GridDisplayToggle enum above
93 */
94export namespace GridDisplayToggle {
95 export function next(current: GridDisplayToggle) {
96 if (current === GridDisplayToggle.GRIDNONE) {
97 return GridDisplayToggle.GRID1000;
98 } else if (current === GridDisplayToggle.GRID1000) {
99 return GridDisplayToggle.GRIDGEO;
100 } else if (current === GridDisplayToggle.GRIDGEO) {
101 return GridDisplayToggle.GRIDBOTH;
102 } else if (current === GridDisplayToggle.GRIDBOTH) {
103 return GridDisplayToggle.GRIDNONE;
104 }
105 }
106}
107
108/**
Sean Condon0c577f62018-11-18 22:40:05 +0000109 * model of the topo2CurrentRegion device props from Device below
110 */
111export interface DeviceProps {
112 latitude: number;
113 longitude: number;
114 name: string;
115 locType: LocationType;
Sean Condon59d31372019-02-02 20:07:00 +0000116 uiType: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000117}
118
119/**
120 * model of the topo2CurrentRegion Loc part of the MetaUi below
121 */
122export interface LocMeta {
123 lng: number;
124 lat: number;
125}
126
127/**
128 * model of the topo2CurrentRegion MetaUi from Device below
129 */
130export interface MetaUi {
131 equivLoc: LocMeta;
132 x: number;
133 y: number;
134}
135
136export interface HostProps {
137 gridX: number;
138 gridY: number;
139 latitude: number;
140 longitude: number;
141 locType: LocationType;
142 name: string;
143}
144
145/**
146 * Implementing SimulationNodeDatum interface into our custom Node class
147 */
Sean Condon50855cf2018-12-23 15:37:42 +0000148export abstract class Node implements UiElement, d3.SimulationNodeDatum {
Sean Condon0c577f62018-11-18 22:40:05 +0000149 // Optional - defining optional implementation properties - required for relevant typing assistance
150 index?: number;
151 x: number;
152 y: number;
153 vx?: number;
154 vy?: number;
155 fx?: number | null;
156 fy?: number | null;
Sean Condon50855cf2018-12-23 15:37:42 +0000157 nodeType: NodeType;
Sean Condon0c577f62018-11-18 22:40:05 +0000158 id: string;
159
160 protected constructor(id) {
161 this.id = id;
162 this.x = 0;
163 this.y = 0;
164 }
165}
166
167/**
168 * model of the topo2CurrentRegion device from Region below
169 */
170export class Device extends Node {
171 id: string;
172 layer: LayerType;
Sean Condon71910542019-02-16 18:16:42 +0000173 location: Location;
Sean Condon0c577f62018-11-18 22:40:05 +0000174 metaUi: MetaUi;
175 master: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000176 online: boolean;
177 props: DeviceProps;
178 type: string;
179
180 constructor(id: string) {
181 super(id);
182 }
183}
184
Sean Condon50855cf2018-12-23 15:37:42 +0000185/**
186 * Model of the ONOS Host element in the topology
187 */
Sean Condon0c577f62018-11-18 22:40:05 +0000188export class Host extends Node {
189 configured: boolean;
190 id: string;
191 ips: string[];
192 layer: LayerType;
Sean Condon0c577f62018-11-18 22:40:05 +0000193 props: HostProps;
194
195 constructor(id: string) {
196 super(id);
197 }
198}
199
200
201/**
202 * model of the topo2CurrentRegion subregion from Region below
203 */
204export class SubRegion extends Node {
205 id: string;
206 location: Location;
207 nDevs: number;
208 nHosts: number;
209 name: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000210 props: RegionProps;
211
212 constructor(id: string) {
213 super(id);
214 }
215}
Sean Condon50855cf2018-12-23 15:37:42 +0000216
217/**
218 * Enumerated values for topology update event types
219 */
220export enum ModelEventType {
221 HOST_ADDED_OR_UPDATED,
222 LINK_ADDED_OR_UPDATED,
223 DEVICE_ADDED_OR_UPDATED,
224 DEVICE_REMOVED,
225 HOST_REMOVED
226}
227
228/**
229 * Enumerated values for topology update event memo field
230 */
231export enum ModelEventMemo {
232 ADDED = 'added',
233 REMOVED = 'removed',
234 UPDATED = 'updated'
235}
236