@@ -5,9 +5,9 @@ import { ProgramBase } from "./program_base";
55import { ViewGraph } from "../types/graphs/viewgraph" ;
66import { ProgramInfo } from "../graphics/renderables/device_info" ;
77import { EchoRequest } from "../packets/icmp" ;
8- import { IpAddress , IPv4Packet } from "../packets/ip" ;
8+ import { IPv4Packet } from "../packets/ip" ;
99import { ViewNetworkDevice } from "../types/view-devices/vNetworkDevice" ;
10- import { EthernetFrame , MacAddress } from "../packets/ethernet" ;
10+ import { EthernetFrame } from "../packets/ethernet" ;
1111import { TOOLTIP_KEYS } from "../utils/constants/tooltips_constants" ;
1212import { Layer } from "../types/layer" ;
1313
@@ -57,40 +57,27 @@ export class SingleEcho extends ProgramBase {
5757 this . dstId ,
5858 this . viewgraph ,
5959 ) ;
60- let src : { ip : IpAddress ; mac : MacAddress } ,
61- dst : { ip : IpAddress ; mac : MacAddress } ,
62- sendingIface : number ;
6360 if ( ! forwardingData ) {
6461 console . warn (
6562 `Device ${ this . srcId } could not send ping to device ${ this . dstId } ` ,
6663 ) ;
67- src = {
68- mac : srcDevice . interfaces [ 0 ] . mac ,
69- ip : srcDevice . interfaces [ 0 ] . ip ,
70- } ;
71- dst = {
72- mac : dstDevice . interfaces [ 0 ] . mac ,
73- ip : dstDevice . interfaces [ 0 ] . ip ,
74- } ;
75- sendingIface = 0 ;
76- } else {
77- ( { src, dst, sendingIface } = forwardingData ) ;
64+ return ;
7865 }
66+ const { src, dst, nextHop, sendingIface } = forwardingData ;
7967 const echoRequest = new EchoRequest ( 0 ) ;
8068 // Wrap in IP datagram
8169 const ipPacket = new IPv4Packet ( src . ip , dst . ip , echoRequest ) ;
8270
83- // Resolve destination MAC address
84- const dstMac = srcDevice . resolveAddress ( dst . ip ) ;
85- if ( ! dstMac ) {
71+ // Resolve next hop MAC address
72+ const nextHopMac = srcDevice . resolveAddress ( nextHop . ip ) ;
73+ if ( ! nextHopMac || ! nextHopMac . mac ) {
8674 console . debug (
87- `Device ${ this . srcId } couldn't resolve MAC address for device with IP ${ dst . ip . toString ( ) } . Program cancelled` ,
75+ `Device ${ this . srcId } couldn't resolve next hop MAC address for device with IP ${ nextHop . ip . toString ( ) } . Program cancelled` ,
8876 ) ;
89- return ;
9077 }
9178
9279 // Wrap in Ethernet frame
93- const ethernetFrame = new EthernetFrame ( src . mac , dst . mac , ipPacket ) ;
80+ const ethernetFrame = new EthernetFrame ( src . mac , nextHopMac . mac , ipPacket ) ;
9481 sendViewPacket ( this . viewgraph , this . srcId , ethernetFrame , sendingIface ) ;
9582 }
9683
0 commit comments