Contents

Filtering on MAC Address

Filtering Ethernet data using MAC addresses.

This example shows how to use blocks in the library xpcethernetlib to filter Ethernet data based on the sender's MAC address. Signal data is sent by the transmitter model, xpcEnetDemo2Tx, running on one target computer, TargetPC1, to the receiver model, xpcEnetDemo2Rx, running on the second target computer, TargetPC2. The "Filter Address" block is used to specify the source MAC addresses that will be accepted. In this simple example, data packets containing one of three source MAC addresses will pass through the Filter Address block in the receiver model:

  1. MAC Address : 40:41:42:43:44:45

  2. MAC Address : 20:21:22:23:24:25

  3. MAC Address : 50:51:52:53:54:55

Note: Only packets with a MAC address 20:21:22:23:24:25 are actually transmitted, received, and plotted.

Requirements

To run this example, you will need two target computers each with a properly installed and configured dedicated Ethernet card (in addition to the Ethernet card used for host-target communications). Refer to the Simulink Real-Time documentation on model-based Ethernet communications for details. Once configured, set the PCI Bus and Slot in the "Ethernet Init" block of xpcEnetDemo2Tx and xpcEnetDemo2Rx to that of the Ethernet card installed in TargetPC1 and TargetPC2 respectively.

Open, Build, and Download the Tx Model to TargetPC1

Click here to open the Tx model: xpcEnetDemo2TxxpcEnetDemo2Tx. This model drives an oscillator with a square wave signal and sends the oscillator input and output signals to the Rx target computer using raw Ethernet. Transmitted data packets have a specified MAC address of 20:21:22:23:24:25.

% Open the model.
mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp(systems, 'xpcEnetDemo2Tx'))
  mdlOpen = 1;
  open_system('xpcEnetDemo2Tx');
end

% Build the model and download to the Tx target computer, TargetPC1.
set_param('xpcEnetDemo2Tx','RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild('xpcEnetDemo2Tx');                     % Build and download application.
### Starting Simulink Real-Time build procedure for model: xpcEnetDemo2Tx
Warning: This model contains blocks that do not handle sample time
changes at runtime. To avoid incorrect results, only change
the sample time in the original model, then rebuild the model. 
### Successful completion of build procedure for model: xpcEnetDemo2Tx
### Looking for target: TargetPC1
### Download model onto target: TargetPC1
% Close the model if we opened it.
if (mdlOpen)
  bdclose('xpcEnetDemo2Tx');
end

Open, Build, and Download the Rx Model to TargetPC2

Click here to open the Rx model: xpcEnetDemo2RxxpcEnetDemo2Rx. This model filters packets based on specified MAC addresses and unpacks the received data for display in target scopes.

% Open the model.
mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp(systems, 'xpcEnetDemo2Rx'))
  mdlOpen = 1;
  open_system('xpcEnetDemo2Rx');
end

% Build the model and download to the Rx target computer, TargetPC2.
set_param('xpcEnetDemo2Rx','RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild('xpcEnetDemo2Rx');                     % Build and download application.
### Starting Simulink Real-Time build procedure for model: xpcEnetDemo2Rx
Warning: This model contains blocks that do not handle sample time
changes at runtime. To avoid incorrect results, only change
the sample time in the original model, then rebuild the model. 
### Successful completion of build procedure for model: xpcEnetDemo2Rx
### Looking for target: TargetPC2
### Download model onto target: TargetPC2
% Close the model if we opened it.
if (mdlOpen)
  bdclose('xpcEnetDemo2Rx');
end

Run both Models

Using the Simulink Real-Time object variables tgTx and tgRx, start the models.

start(tgTx); % Start the Tx model.
start(tgRx); % Start the Rx model.
pause(5);    % Let the models run for at least 5 sec.

Display the Tx Target Computer Scope

Take a snapshot of the Tx target computer video display. Plotted is the signal data that's sent to the Rx target computer via raw Ethernet.

tgTx.viewTargetScreen

Display the Rx Target Computer Scopes

Take a snapshot of the Rx target computer video display. Plotted is the signal data received from the Tx target computer via raw Ethernet. Note that data passes through only one of the MAC address filters.

tgRx.viewTargetScreen

Stop both Models

When done, stop the models from running.

stop(tgTx); % Stop the Tx model.
stop(tgRx); % Stop the Rx model.

% EOF xpcEnetDemo2.m
Was this topic helpful?