11import { EthernetFrame , MacAddress } from "../../packets/ethernet" ;
2- import { DataGraph , DataNode , DeviceId } from "../graphs/datagraph" ;
2+ import { DataGraph , DataNode } from "../graphs/datagraph" ;
33import { DeviceType , NetworkInterface } from "../view-devices/vDevice" ;
44import { Position } from "../common" ;
5+ import { IpAddress } from "../../packets/ip" ;
56
67export abstract class DataDevice {
78 private static idCounter = 1 ;
89
910 id : number ;
1011 x : number ;
1112 y : number ;
12- mac : MacAddress ;
1313 datagraph : DataGraph ;
1414 interfaces : NetworkInterface [ ] = [ ] ;
1515
@@ -22,7 +22,6 @@ export abstract class DataDevice {
2222 constructor ( graphData : DataNode , datagraph : DataGraph ) {
2323 this . x = graphData . x ;
2424 this . y = graphData . y ;
25- this . mac = MacAddress . parse ( graphData . mac ) ;
2625 if ( graphData . id ) {
2726 this . id = graphData . id ;
2827 DataDevice . setIdCounter ( graphData . id ) ;
@@ -33,6 +32,7 @@ export abstract class DataDevice {
3332 this . interfaces . push ( {
3433 name : iface . name ,
3534 mac : MacAddress . parse ( iface . mac ) ,
35+ ip : iface . ip !== undefined ? IpAddress . parse ( iface . ip ) : undefined ,
3636 } ) ;
3737 } ) ;
3838 this . datagraph = datagraph ;
@@ -48,16 +48,20 @@ export abstract class DataDevice {
4848 type : this . getType ( ) ,
4949 x : this . x ,
5050 y : this . y ,
51- mac : this . mac . toString ( ) ,
5251 interfaces : this . interfaces . map ( ( iface ) => ( {
5352 name : iface . name ,
5453 mac : iface . mac . toString ( ) ,
54+ ip : iface . ip !== undefined ? iface . ip . toString ( ) : undefined ,
5555 } ) ) ,
5656 } ;
5757 }
5858
5959 abstract getType ( ) : DeviceType ;
6060
61+ ownMac ( mac : MacAddress ) : boolean {
62+ return this . interfaces . some ( ( iface ) => iface . mac . equals ( mac ) ) ;
63+ }
64+
6165 getPosition ( ) : Position {
6266 return { x : this . x , y : this . y } ;
6367 }
@@ -66,5 +70,5 @@ export abstract class DataDevice {
6670 * Returns the id for the next device to send the packet to, or
6771 * null if there’s no next device to send the packet.
6872 * */
69- abstract receiveFrame ( frame : EthernetFrame , senderId : DeviceId ) : void ;
73+ abstract receiveFrame ( frame : EthernetFrame , iface : number ) : void ;
7074}
0 commit comments