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