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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

cache-hit()is-co<strong>ns</strong>istent()Ysend cached pageignore the requestget-request()Nrefetch-pending()cache-miss()send-request()refetch()Figure 39.4: H<strong>and</strong>ling of incoming request in Http/Cacheget-request 〈client〉 〈type〉 〈pageid〉cache-miss 〈client〉 〈type〉 〈pageid〉cache-hit 〈client〉 〈type〉 〈pageid〉is-co<strong>ns</strong>istent 〈client〉 〈type〉 〈pageid〉refetch 〈client〉 〈type〉 〈pageid〉<strong>The</strong> entry point of processing any request. It checks if the requested page $pageidexists in the cache’s page pool, then call either cache-hit or cache-miss.This cache doesn’t have the page. Send a request to server (or parent cache) torefetch the page if it hasn’t already done so. Register $client in a list so th<strong>at</strong> whenthe cache gets the page, it’ll forward the page to all clients who have requested thepage.Checks the valid<strong>at</strong>ity of the cached page. If it’s valid, send $client the cached page,otherwise refetch the page.Retur<strong>ns</strong> 1 if $pageid is valid. This is intended to be overridden by subclasses.Refetch an invalid page from server. This is intended to be overridden by subclasses.39.8 Putting together: a simple exampleWe have seen all the pieces, now we present a script which provides a complete view of all pieces together. First, we buildtopology <strong>and</strong> other usual initializ<strong>at</strong>io<strong>ns</strong>:set <strong>ns</strong> [new Simul<strong>at</strong>or]# Cre<strong>at</strong>e topology/routingset node(c) [$<strong>ns</strong> node]set node(e) [$<strong>ns</strong> node]set node(s) [$<strong>ns</strong> node]$<strong>ns</strong> duplex-link $node(s) $node(e) 1.5Mb 50ms DropTail$<strong>ns</strong> duplex-link $node(e) $node(c) 10Mb 2ms DropTail$<strong>ns</strong> rtproto SessionNext we cre<strong>at</strong>e the Http objects:# HTTP logsset log [open "http.log" w]# Cre<strong>at</strong>e page pool as a central page gener<strong>at</strong>or. Use PagePool/M<strong>at</strong>hset pgp [new PagePool/M<strong>at</strong>h]set tmp [new R<strong>and</strong>omVariable/Co<strong>ns</strong>tant];## Page size gener<strong>at</strong>or$tmp set val_ 1024;## average page size$pgp ranvar-size $tmp355

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

Saved successfully!

Ooh no, something went wrong!