/** * routestrategy.h * Implemented by Blueprint Technologies, Inc. * This file defines startegy classes to determine * how packet routing through a network will be handled. */ #ifndef _routestrategy_h #define _routestrategy_h /** * Include the data types with which the strategy works. */ #include "routetypes.h" /** * This class declares an interface common to all * classes involved in determining how to route packets * through a complex network. */ class RouteStrategy { public: /** * This may not be entirely true-to-life. Based on where * the packet is now, determine the next node to send the packet * to get that packet to its target address. This method takes * a target network address and returns the next network * address the packet should go to. */ virtual NetworkAddress& getNextHop( NetworkAddress& TargetAddress ) = 0; }; /** * This implementation of the RouteStrategy class determines * how to send a data packet through a set of networks based * on a least cost approach. */ class MinimalCostRouteStrategy: public RouteStrategy { public: virtual NetworkAddress& getNextHop( NetworkAddress& TargetAddress ) { NetworkAddress nextAddress; return nextAddress; }; }; /** * This implementation of the RouteStrategy class determines * how to send a data packet through a set of networks based * on a least amount of time to target approach. */ class MinimalTimeRouteStrategy: public RouteStrategy { public: virtual NetworkAddress& getNextHop( NetworkAddress& TargetAddress ) { NetworkAddress nextAddress; return nextAddress; }; }; /** * This class is the contextual interface for the client to * determine how to route a packet through a network. */ class Router { private: /** * This is the strategy which is stored as an abstract * pointer to a concrete RouteStrategy object. */ RouteStrategy* strategy; public: /** * Default constructor. */ Router() { strategy = (RouteStrategy *) 0; }; public: /** * This method defines the main interface a client * will use to find a route for a data packet. */ void routePacket( DataPacket& packet, NetworkAddress& targetAddress ) { NetworkAddress nextAddress; nextAddress = strategy -> getNextHop( targetAddress ); /** * Send the packet to that address. */ }; public: /** * These method represent the accessors used for * changing the route strategy during run-time. */ RouteStrategy* getStrategy() { return strategy; }; void setStrategy( RouteStrategy* newStrategy) { strategy = newStrategy; }; }; #endif