Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 16 | import {Node, UiElement} from './node'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 17 | import * as d3 from 'd3'; |
| 18 | |
| 19 | export enum LinkType { |
| 20 | UiRegionLink, |
| 21 | UiDeviceLink, |
| 22 | UiEdgeLink |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * model of the topo2CurrentRegion region rollup from Region below |
| 27 | * |
| 28 | */ |
| 29 | export interface RegionRollup { |
| 30 | id: string; |
| 31 | epA: string; |
| 32 | epB: string; |
| 33 | portA: string; |
| 34 | portB: string; |
| 35 | type: LinkType; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Implementing SimulationLinkDatum interface into our custom Link class |
| 40 | */ |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 41 | export class Link implements UiElement, d3.SimulationLinkDatum<Node> { |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 42 | // Optional - defining optional implementation properties - required for relevant typing assistance |
| 43 | index?: number; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 44 | id: string; // The id of the link in the format epA/portA~epB/portB |
| 45 | epA: string; // The name of the device or host at one end |
| 46 | epB: string; // The name of the device or host at the other end |
| 47 | portA: string; // The number of the port at one end |
| 48 | portB: string; // The number of the port at the other end |
| 49 | type: LinkType; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 50 | |
| 51 | // Must - defining enforced implementation properties |
| 52 | source: Node; |
| 53 | target: Node; |
| 54 | |
| 55 | constructor(source, target) { |
| 56 | this.source = source; |
| 57 | this.target = target; |
| 58 | } |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 59 | |
| 60 | linkTypeStr(): string { |
| 61 | return LinkType[this.type]; |
| 62 | } |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /** |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 66 | * model of the topo2CurrentRegion region link from Region |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 67 | */ |
| 68 | export class RegionLink extends Link { |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 69 | rollup: RegionRollup[]; // Links in sub regions represented by this one link |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 70 | |
| 71 | constructor(type: LinkType, nodeA: Node, nodeB: Node) { |
| 72 | super(nodeA, nodeB); |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 73 | this.type = type; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * model of the highlights that are sent back from WebSocket when traffic is shown |
| 79 | */ |
| 80 | export interface LinkHighlight { |
| 81 | id: string; |
| 82 | css: string; |
| 83 | label: string; |
| 84 | } |