Sometimes you might want a packet handler to respond to more than one type of packet, in which case you have basically two choices. If there's just a few packet types involved, you can create multiple reflexes that associate the same handler with each different type -- that's what we did in forward::cpp. But if there's many packet types involved, that's a pain.

As an alternative, the core software allows you to register a 'catch-all' handler that will be called if no other packet handler seems appropriate. The SFBReactor::otherwise() method is used to register such a packet handler.

In this sketch, any otherwise unhandled packets arriving on the east or west faces are forwarded out the opposite face. In addition, for classified Department of IXM Security (DIS) purposes, a copy of the forwarded packet is 'L'ogged to the north face.

// Forward otherwise unhandled packets between east and west only,
// logging north a copy of all forwarded packets

void doForwardTee(u8 * packet) {

  // Send a copy of the packet out the opposite face of its source; so
  // if source is EAST, print to WEST, and vv.  (NORTH and SOUTH can't
  // arise as sources here, because there are no reflexes for that)


  // In addition, log forwarded packets to the north.  We'll send
  // packet type 'L's, which is conventionally used for logging by the
  // core software

  facePrint(NORTH,"L from ");
  facePrint(NORTH,FACE_CODE(packetSource(packet))); // prints 'E' or 'W' (in this case)
  facePrint(NORTH,": ");

void setup() {
  EastFace.otherwise(doForwardTee);    // Make doForwardTee the catch-all for EAST 
  WestFace.otherwise(doForwardTee);    // Make doForwardTee the catch-all for WEST 
void loop() { /* Nothing to do! */ }

Generated on Fri Apr 22 06:54:11 2011 for SFB by doxygen 1.5.9