blob: ce22e99cf4b4ca16f49d342997626d2f3265dd28 [file] [log] [blame]
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as d3 from 'd3';
import {LocationType} from '../../backgroundsvg/backgroundsvg.component';
import {LayerType, Location, NodeType, RegionProps} from './regions';
import {MetaUi} from 'gui2-fw-lib';
export interface UiElement {
index?: number;
id: string;
}
export namespace LabelToggle {
/**
* Toggle state for how device labels should be displayed
*/
export enum Enum {
NONE,
ID,
NAME
}
/**
* Add the method 'next()' to the LabelToggle enum above
*/
export function next(current: Enum) {
if (current === Enum.NONE) {
return Enum.ID;
} else if (current === Enum.ID) {
return Enum.NAME;
} else if (current === Enum.NAME) {
return Enum.NONE;
}
}
}
export namespace HostLabelToggle {
/**
* Toggle state for how host labels should be displayed
*/
export enum Enum {
NONE,
NAME,
IP,
MAC
}
/**
* Add the method 'next()' to the HostLabelToggle enum above
*/
export function next(current: Enum) {
if (current === Enum.NONE) {
return Enum.NAME;
} else if (current === Enum.NAME) {
return Enum.IP;
} else if (current === Enum.IP) {
return Enum.MAC;
} else if (current === Enum.MAC) {
return Enum.NONE;
}
}
}
export namespace GridDisplayToggle {
/**
* Toggle state for how the grid should be displayed
*/
export enum Enum {
GRIDNONE,
GRID1000,
GRIDGEO,
GRIDBOTH
}
/**
* Add the method 'next()' to the GridDisplayToggle enum above
*/
export function next(current: Enum) {
if (current === Enum.GRIDNONE) {
return Enum.GRID1000;
} else if (current === Enum.GRID1000) {
return Enum.GRIDGEO;
} else if (current === Enum.GRIDGEO) {
return Enum.GRIDBOTH;
} else if (current === Enum.GRIDBOTH) {
return Enum.GRIDNONE;
}
}
}
/**
* model of the topo2CurrentRegion device props from Device below
*/
export interface DeviceProps {
latitude: number;
longitude: number;
name: string;
locType: LocationType;
uiType: string;
channelId: string;
managementAddress: string;
protocol: string;
}
export interface HostProps {
gridX: number;
gridY: number;
latitude: number;
longitude: number;
locType: LocationType;
name: string;
}
/**
* Implementing SimulationNodeDatum interface into our custom Node class
*/
export abstract class Node implements UiElement, d3.SimulationNodeDatum {
// Optional - defining optional implementation properties - required for relevant typing assistance
index?: number;
x: number;
y: number;
vx?: number;
vy?: number;
fx?: number | null;
fy?: number | null;
nodeType: NodeType;
id: string;
protected constructor(id) {
this.id = id;
this.x = 0;
this.y = 0;
}
}
/**
* model of the topo2CurrentRegion device from Region below
*/
export class Device extends Node {
id: string;
layer: LayerType;
location: Location;
metaUi: MetaUi;
master: string;
online: boolean;
props: DeviceProps;
type: string;
constructor(id: string) {
super(id);
}
}
/**
* Model of the ONOS Host element in the topology
*/
export class Host extends Node {
configured: boolean;
id: string;
ips: string[];
layer: LayerType;
props: HostProps;
constructor(id: string) {
super(id);
}
}
/**
* model of the topo2CurrentRegion subregion from Region below
*/
export class SubRegion extends Node {
id: string;
location: Location;
nDevs: number;
nHosts: number;
name: string;
props: RegionProps;
constructor(id: string) {
super(id);
}
}
/**
* Enumerated values for topology update event types
*/
export enum ModelEventType {
HOST_ADDED_OR_UPDATED,
LINK_ADDED_OR_UPDATED,
DEVICE_ADDED_OR_UPDATED,
DEVICE_REMOVED,
HOST_REMOVED
}
/**
* Enumerated values for topology update event memo field
*/
export enum ModelEventMemo {
ADDED = 'added',
REMOVED = 'removed',
UPDATED = 'updated'
}