def link_ports(self, nffg, flowid1, flowid2, port1, port2):
        if not nffg.existPort(port1):
            raise Exception("Port with id:"+port1+" is invalid")

        if not nffg.existPort(port2):
            raise Exception("Port with id:"+port2+" is invalid")

        nffg.addFlowRule(FlowRule(flowid1, 1, Match(port1), [Action(port2)]))
        nffg.addFlowRule(FlowRule(flowid2, 1, Match(port2), [Action(port1)]))
示例#2
0
    def set_default(self, nffg, out_port):
        flowrules = nffg.getFlowRulesStartingWith("LB_DEFAULT_")
        for flowrule in flowrules:
            logging.debug("removing flow rule with name '%s'  " %
                          (flowrule.id))
            nffg.removeFlowRule(flowrule.id)

        logging.debug("setting default flow rule : port_in=%s -> %s " %
                      (self.port_in, out_port))

        nffg.addFlowRule(
            FlowRule("LB_DEFAULT_" + str(self.counter), 1,
                     Match(port_in=self.port_in), [Action(out_port)]))

        logging.debug("setting reply flow rule : port_in=%s -> %s " %
                      (out_port, self.port_in))

        nffg.addFlowRule(
            FlowRule("LB_REPLY_" + str(self.counter), 2,
                     Match(port_in=out_port), [Action(self.port_in)]))
        self.counter = self.counter + 1
示例#3
0
    def add_balance(self, nffg, host_mac, out_port):

        flow_rule_name = "LB_" + host_mac.replace(":", "")

        logging.info(
            "setting flow rule : port_in=%s,source_mac=%s,dest_mac=%s -> %s " %
            (self.port_in, host_mac, self.mac, out_port))

        if self.exist_balance(nffg, host_mac):
            raise Exception(
                "Already exist a load-balancing rule for source_mac=%s!" %
                host_mac)

        nffg.addFlowRule(
            FlowRule(
                flow_rule_name, 2,
                Match(port_in=self.port_in,
                      source_mac=host_mac,
                      dest_mac=self.mac), [Action(out_port)]))