12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

An Http/Server object waits for incoming requests after simul<strong>at</strong>ion starts. Usually clients <strong>and</strong> caches initi<strong>at</strong>es connection toan Http/Server. But it still has its own connect method, which allows an Http/Server object to actively connect to a certaincache (or client). Sometimes this is useful, as explained in Test/TLC1::set-groups{} in <strong>ns</strong>/tcl/test/test-suite-webcache.tcl.An Http/Server object accepts two types of requests: GET <strong>and</strong> IMS. GET request models normal client requests. For everyGET request, it retur<strong>ns</strong> the <strong>at</strong>tributes of the requested page. IMS request models If-Modified-Since used by TTL algorithmsfor cache co<strong>ns</strong>istency. For every IMS (If-Modified-Since) request, it compares the page modific<strong>at</strong>ion time given in the request<strong>and</strong> th<strong>at</strong> of the page in its PagePool. If the time indic<strong>at</strong>ed in the request is older, it sends back a respo<strong>ns</strong>e with very small size,otherwise it retur<strong>ns</strong> all of the page <strong>at</strong>tributes with respo<strong>ns</strong>e size equal the real page size.39.7 Web cacheCurrently 6 types of web caches are implemented, including the base class Http/Cache. Its five derived subclasses implement5 types of cache co<strong>ns</strong>istency algorithms: Plain old TTL, adaptive TTL, Omniscient TTL, Hierarchical multicast invalid<strong>at</strong>ion,<strong>and</strong> hierarchical multicast invalid<strong>at</strong>ion plus direct request.In the following we’ll only describe the base class Http/Cache, because all the subclasses involves discussion of cache co<strong>ns</strong>istencyalgorithms <strong>and</strong> it does not seem to be appropri<strong>at</strong>e here.39.7.1 Http/CacheClass Http/Cache models behavior of a simple HTTP cache with infinite size. It doesn’t contain removal algorithm, norco<strong>ns</strong>istency algorithm. It is not intended to be used by itself. R<strong>at</strong>her, it is meant to be a base class for experimenting withvarious cache co<strong>ns</strong>istency algorithms <strong>and</strong> other cache algorithms.Cre<strong>at</strong>ion <strong>and</strong> startup Cre<strong>at</strong>ing an Http/Cache requires the same set of parameters as Http/Client <strong>and</strong> Http/Server. Aftercre<strong>at</strong>ion, a cache needs to connect to a certain server. Note th<strong>at</strong> this cre<strong>at</strong>ion can also be done dynamically, when a requestcomes in <strong>and</strong> the cache finds th<strong>at</strong> it’s not connected to the server. However, we do not model this behavior in current code.Following code is an example:set cache [new HttpCache $<strong>ns</strong> $node]$cache connect $server;# <strong>at</strong>tach cache to $node;# connect to $serverLike Http/Server, an Http/Cache object waits for requests (<strong>and</strong> packets from server) after it’s initialized as above. Whenhierarchical caching is used, the following can be used to cre<strong>at</strong>e the hierarchy:$cache set-parent $parent;# set parent cacheCurrently all TTL <strong>and</strong> multicast invalid<strong>at</strong>ion caches support hierarchical caching. However, only the two multicast invalid<strong>at</strong>ioncaches allows multiple cache hierarchies to inter-oper<strong>at</strong>e.OTcl methods Although Http/Cache is a SplitObject, all of its methods are in OTcl. Most of them are used to process anincoming request. <strong>The</strong>ir rel<strong>at</strong>io<strong>ns</strong> can be illustr<strong>at</strong>ed with the flowchart below, followed by explain<strong>at</strong>io<strong>ns</strong>:354

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!