blob: b4e62cc4016032140e33d22135806236d9a897cf [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';
Sean Condonee5d4b92019-03-11 19:57:34 +000019import {MetaUi} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000020
Sean Condon50855cf2018-12-23 15:37:42 +000021export interface UiElement {
22 index?: number;
23 id: string;
24}
25
Sean Condon0c577f62018-11-18 22:40:05 +000026export namespace LabelToggle {
Sean Condonff85fbe2019-03-16 14:28:46 +000027 /**
28 * Toggle state for how device labels should be displayed
29 */
30 export enum Enum {
31 NONE,
32 ID,
33 NAME
34 }
35
36 /**
37 * Add the method 'next()' to the LabelToggle enum above
38 */
39 export function next(current: Enum) {
40 if (current === Enum.NONE) {
41 return Enum.ID;
42 } else if (current === Enum.ID) {
43 return Enum.NAME;
44 } else if (current === Enum.NAME) {
45 return Enum.NONE;
Sean Condon0c577f62018-11-18 22:40:05 +000046 }
47 }
48}
49
Sean Condon021f0fa2018-12-06 23:31:11 -080050export namespace HostLabelToggle {
Sean Condonff85fbe2019-03-16 14:28:46 +000051 /**
52 * Toggle state for how host labels should be displayed
53 */
54 export enum Enum {
55 NONE,
56 NAME,
57 IP,
58 MAC
59 }
60
61 /**
62 * Add the method 'next()' to the HostLabelToggle enum above
63 */
64 export function next(current: Enum) {
65 if (current === Enum.NONE) {
66 return Enum.NAME;
67 } else if (current === Enum.NAME) {
68 return Enum.IP;
69 } else if (current === Enum.IP) {
70 return Enum.MAC;
71 } else if (current === Enum.MAC) {
72 return Enum.NONE;
Sean Condon021f0fa2018-12-06 23:31:11 -080073 }
74 }
75}
76
Sean Condon71910542019-02-16 18:16:42 +000077export namespace GridDisplayToggle {
Sean Condonff85fbe2019-03-16 14:28:46 +000078 /**
79 * Toggle state for how the grid should be displayed
80 */
81 export enum Enum {
82 GRIDNONE,
83 GRID1000,
84 GRIDGEO,
85 GRIDBOTH
86 }
87
88 /**
89 * Add the method 'next()' to the GridDisplayToggle enum above
90 */
91 export function next(current: Enum) {
92 if (current === Enum.GRIDNONE) {
93 return Enum.GRID1000;
94 } else if (current === Enum.GRID1000) {
95 return Enum.GRIDGEO;
96 } else if (current === Enum.GRIDGEO) {
97 return Enum.GRIDBOTH;
98 } else if (current === Enum.GRIDBOTH) {
99 return Enum.GRIDNONE;
Sean Condon71910542019-02-16 18:16:42 +0000100 }
101 }
102}
103
104/**
Sean Condon0c577f62018-11-18 22:40:05 +0000105 * model of the topo2CurrentRegion device props from Device below
106 */
107export interface DeviceProps {
108 latitude: number;
109 longitude: number;
Sean Condon28884332019-03-21 14:07:00 +0000110 gridX: number;
111 gridY: number;
Sean Condon0c577f62018-11-18 22:40:05 +0000112 name: string;
113 locType: LocationType;
Sean Condon59d31372019-02-02 20:07:00 +0000114 uiType: string;
Sean Condonee545762019-03-09 10:43:58 +0000115 channelId: string;
116 managementAddress: string;
117 protocol: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000118}
119
Sean Condon0c577f62018-11-18 22:40:05 +0000120export interface HostProps {
121 gridX: number;
122 gridY: number;
123 latitude: number;
124 longitude: number;
125 locType: LocationType;
126 name: string;
127}
128
129/**
130 * Implementing SimulationNodeDatum interface into our custom Node class
131 */
Sean Condon50855cf2018-12-23 15:37:42 +0000132export abstract class Node implements UiElement, d3.SimulationNodeDatum {
Sean Condon0c577f62018-11-18 22:40:05 +0000133 // Optional - defining optional implementation properties - required for relevant typing assistance
134 index?: number;
135 x: number;
136 y: number;
137 vx?: number;
138 vy?: number;
139 fx?: number | null;
140 fy?: number | null;
Sean Condon50855cf2018-12-23 15:37:42 +0000141 nodeType: NodeType;
Sean Condon0c577f62018-11-18 22:40:05 +0000142 id: string;
143
144 protected constructor(id) {
145 this.id = id;
146 this.x = 0;
147 this.y = 0;
148 }
149}
150
151/**
152 * model of the topo2CurrentRegion device from Region below
153 */
154export class Device extends Node {
155 id: string;
156 layer: LayerType;
Sean Condon71910542019-02-16 18:16:42 +0000157 location: Location;
Sean Condon0c577f62018-11-18 22:40:05 +0000158 metaUi: MetaUi;
159 master: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000160 online: boolean;
161 props: DeviceProps;
162 type: string;
163
164 constructor(id: string) {
165 super(id);
166 }
167}
168
Sean Condon50855cf2018-12-23 15:37:42 +0000169/**
170 * Model of the ONOS Host element in the topology
171 */
Sean Condon0c577f62018-11-18 22:40:05 +0000172export class Host extends Node {
173 configured: boolean;
174 id: string;
175 ips: string[];
176 layer: LayerType;
Sean Condon0c577f62018-11-18 22:40:05 +0000177 props: HostProps;
178
179 constructor(id: string) {
180 super(id);
181 }
182}
183
184
185/**
186 * model of the topo2CurrentRegion subregion from Region below
187 */
188export class SubRegion extends Node {
189 id: string;
190 location: Location;
191 nDevs: number;
192 nHosts: number;
193 name: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000194 props: RegionProps;
195
196 constructor(id: string) {
197 super(id);
198 }
199}
Sean Condon50855cf2018-12-23 15:37:42 +0000200
201/**
202 * Enumerated values for topology update event types
203 */
204export enum ModelEventType {
205 HOST_ADDED_OR_UPDATED,
206 LINK_ADDED_OR_UPDATED,
207 DEVICE_ADDED_OR_UPDATED,
208 DEVICE_REMOVED,
209 HOST_REMOVED
210}
211
212/**
213 * Enumerated values for topology update event memo field
214 */
215export enum ModelEventMemo {
216 ADDED = 'added',
217 REMOVED = 'removed',
218 UPDATED = 'updated'
219}
220