Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

Dynamic Policies

joshreich edited this page Dec 5, 2014 · 6 revisions

Query policies are often used to drive changes to other dynamic policies. These dynamic policies have behavior (defined by self.policy ) that changes over time, according to the programmer's specification. For example, the routine round_robin takes the first packet from a new client (source IP address) and updates the policy's behavior (by assigning self.policy to a new value) so all future packets from this source are assigned to the next server in the sequence (by rewriting the destination IP address); packets from all other clients are treated as before. After updating the policy, round_robin also moves the "currently up" server to the next server in the list.

 def round_robin(self,pkt):
   self.policy = if_(match(srcip=pkt['srcip']),
                     modify(dstip=self.server),
                     self.policy)
   self.client += 1
   self.server = self.servers[self.client % m]

The programmer creates a new ``round-robin load balancer'' dynamic policy class rrlb by subclassing DynamicPolicy and providing an initialization method that registers round_robin as a callback routine:

 class rrlb(DynamicPolicy):
   def __init__(self,s,servers):
     self.switch = s
     self.servers = servers 
     ...
     Q.register_callback(self.round_robin)
     self.policy = match(dstport=80) >> Q

   def round_robin(self,pkt):
     ...

Note that here the query Q is defined as in the previous subsection; the only difference is that the the programmer registers round_robin as the callback, instead of printer. The programmer then creates a new instance of rrlb (say one running on switch 3 and sending requests to server replicas at 2.2.2.8 and 2.2.2.9) in the standard way

 servers = [IP('2.2.2.8'),IP('2.2.2.9')]
 rrlb_on_switch3 = rrlb(3,servers)

producing a policy that can be used in exactly the same ways as any other. For example, to compose server load balancing with routing, we might write the following. rrlb_on_switch3 >> route

Clone this wiki locally