blob: de70eb451c038d807c877116466a9dfdbcc1ac11 [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 Condon0c577f62018-11-18 22:40:05 +000082 * model of the topo2CurrentRegion device props from Device below
83 */
84export interface DeviceProps {
85 latitude: number;
86 longitude: number;
87 name: string;
88 locType: LocationType;
Sean Condon59d31372019-02-02 20:07:00 +000089 uiType: string;
Sean Condon0c577f62018-11-18 22:40:05 +000090}
91
92/**
93 * model of the topo2CurrentRegion Loc part of the MetaUi below
94 */
95export interface LocMeta {
96 lng: number;
97 lat: number;
98}
99
100/**
101 * model of the topo2CurrentRegion MetaUi from Device below
102 */
103export interface MetaUi {
104 equivLoc: LocMeta;
105 x: number;
106 y: number;
107}
108
109export interface HostProps {
110 gridX: number;
111 gridY: number;
112 latitude: number;
113 longitude: number;
114 locType: LocationType;
115 name: string;
116}
117
118/**
119 * Implementing SimulationNodeDatum interface into our custom Node class
120 */
Sean Condon50855cf2018-12-23 15:37:42 +0000121export abstract class Node implements UiElement, d3.SimulationNodeDatum {
Sean Condon0c577f62018-11-18 22:40:05 +0000122 // Optional - defining optional implementation properties - required for relevant typing assistance
123 index?: number;
124 x: number;
125 y: number;
126 vx?: number;
127 vy?: number;
128 fx?: number | null;
129 fy?: number | null;
Sean Condon50855cf2018-12-23 15:37:42 +0000130 nodeType: NodeType;
Sean Condon0c577f62018-11-18 22:40:05 +0000131 id: string;
132
133 protected constructor(id) {
134 this.id = id;
135 this.x = 0;
136 this.y = 0;
137 }
138}
139
140/**
141 * model of the topo2CurrentRegion device from Region below
142 */
143export class Device extends Node {
144 id: string;
145 layer: LayerType;
146 location: LocationType;
147 metaUi: MetaUi;
148 master: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000149 online: boolean;
150 props: DeviceProps;
151 type: string;
152
153 constructor(id: string) {
154 super(id);
155 }
156}
157
Sean Condon50855cf2018-12-23 15:37:42 +0000158/**
159 * Model of the ONOS Host element in the topology
160 */
Sean Condon0c577f62018-11-18 22:40:05 +0000161export class Host extends Node {
162 configured: boolean;
163 id: string;
164 ips: string[];
165 layer: LayerType;
Sean Condon0c577f62018-11-18 22:40:05 +0000166 props: HostProps;
167
168 constructor(id: string) {
169 super(id);
170 }
171}
172
173
174/**
175 * model of the topo2CurrentRegion subregion from Region below
176 */
177export class SubRegion extends Node {
178 id: string;
179 location: Location;
180 nDevs: number;
181 nHosts: number;
182 name: string;
Sean Condon0c577f62018-11-18 22:40:05 +0000183 props: RegionProps;
184
185 constructor(id: string) {
186 super(id);
187 }
188}
Sean Condon50855cf2018-12-23 15:37:42 +0000189
190/**
191 * Enumerated values for topology update event types
192 */
193export enum ModelEventType {
194 HOST_ADDED_OR_UPDATED,
195 LINK_ADDED_OR_UPDATED,
196 DEVICE_ADDED_OR_UPDATED,
197 DEVICE_REMOVED,
198 HOST_REMOVED
199}
200
201/**
202 * Enumerated values for topology update event memo field
203 */
204export enum ModelEventMemo {
205 ADDED = 'added',
206 REMOVED = 'removed',
207 UPDATED = 'updated'
208}
209