Exemple #1
0
    def flow_timer(self, dp):
        if dp in self.dp_stats:
            match = openflow.ofp_match()
            match.wildcards = 0xffffffff
            self.ctxt.send_flow_stats_request(dp, match,  0xff)
	    #lg.debug("Mandei o pedido de flowstats para o dpid " + mac_to_str(dp))
            self.post_callback(self.dp_poll_period[dp]['flow'], lambda : self.flow_timer(dp))
Exemple #2
0
 def aggr_timer(self, dp):
     if dp in self.dp_stats:
         match = openflow.ofp_match()
         match.wildcards = 0xffffffff
         self.ctxt.send_aggregate_stats_request(dp, match,  0xff)
         self.post_callback(self.dp_poll_period[dp]['aggr'], lambda : self.aggr_timer(dp))
Exemple #3
0
 def aggregate_timer(self, dpid):
     flow = ofp_match()
     flow.wildcards = 0xffff
     self.ctxt.send_aggregate_stats_request(dpid, flow, 0xff)
     self.post_callback(MONITOR_TABLE_PERIOD,
                        lambda: self.aggregate_timer(dpid))
Exemple #4
0
def set_match(attrs):
    m = openflow.ofp_match()
    wildcards = 0
    num_entries = 0

    if attrs.has_key(core.IN_PORT):
        m.in_port = htons(attrs[core.IN_PORT])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_IN_PORT

    if attrs.has_key(core.DL_VLAN):
        m.dl_vlan = htons(attrs[core.DL_VLAN])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_VLAN

    if attrs.has_key(core.DL_VLAN_PCP):
        m.dl_vlan_pcp = attrs[core.DL_VLAN_PCP]
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_VLAN_PCP

    if attrs.has_key(core.DL_SRC):
        v = convert_to_eaddr(attrs[core.DL_SRC])
        if v == None:
            print "invalid ethernet addr"
            return None
        m.set_dl_src(v.octet)
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_SRC

    if attrs.has_key(core.DL_DST):
        v = convert_to_eaddr(attrs[core.DL_DST])
        if v == None:
            print "invalid ethernet addr"
            return None
        m.set_dl_dst(v.octet)
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_DST

    if attrs.has_key(core.DL_TYPE):
        m.dl_type = htons(attrs[core.DL_TYPE])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_TYPE

    if attrs.has_key(core.NW_SRC):
        v = convert_to_ipaddr(attrs[core.NW_SRC])
        if v == None:
            print "invalid ip addr"
            return None
        m.nw_src = v
        num_entries += 1

        if attrs.has_key(core.NW_SRC_N_WILD):
            n_wild = attrs[core.NW_SRC_N_WILD]
            if n_wild > 31:
                wildcards |= openflow.OFPFW_NW_SRC_MASK
            elif n_wild >= 0:
                wildcards |= n_wild << openflow.OFPFW_NW_SRC_SHIFT
            else:
                print "invalid nw_src wildcard bit count", n_wild
                return None
            num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_SRC_MASK

    if attrs.has_key(core.NW_DST):
        v = convert_to_ipaddr(attrs[core.NW_DST])
        if v == None:
            print "invalid ip addr"
            return None
        m.nw_dst = v
        num_entries += 1

        if attrs.has_key(core.NW_DST_N_WILD):
            n_wild = attrs[core.NW_DST_N_WILD]
            if n_wild > 31:
                wildcards |= openflow.OFPFW_NW_DST_MASK
            elif n_wild >= 0:
                wildcards |= n_wild << openflow.OFPFW_NW_DST_SHIFT
            else:
                print "invalid nw_dst wildcard bit count", n_wild
                return None
            num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_DST_MASK

    if attrs.has_key(core.NW_PROTO):
        m.nw_proto = attrs[core.NW_PROTO]
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_PROTO

    if attrs.has_key(core.NW_TOS):
        m.nw_tos = attrs[core.NW_TOS]
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_TOS

    if attrs.has_key(core.TP_SRC):
        m.tp_src = htons(attrs[core.TP_SRC])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_TP_SRC

    if attrs.has_key(core.TP_DST):
        m.tp_dst = htons(attrs[core.TP_DST])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_TP_DST

    if num_entries != len(attrs.keys()):
        print "undefined flow attribute type in attrs", attrs
        return None

    m.wildcards = c_htonl(wildcards)
    return m
Exemple #5
0
 def aggregate_timer(self, dpid):
     flow = ofp_match() 
     flow.wildcards = 0xffff
     self.ctxt.send_aggregate_stats_request(dpid, flow,  0xff)
     self.post_callback(MONITOR_TABLE_PERIOD, lambda : self.aggregate_timer(dpid))
Exemple #6
0
def set_match(attrs):
    m = openflow.ofp_match()
    wildcards = 0
    num_entries = 0

    if attrs.has_key(core.IN_PORT):
        m.in_port = htons(attrs[core.IN_PORT])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_IN_PORT

    if attrs.has_key(core.DL_VLAN):
        m.dl_vlan = htons(attrs[core.DL_VLAN])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_VLAN

    if attrs.has_key(core.DL_VLAN_PCP):
        m.dl_vlan = htons(attrs[core.DL_VLAN_PCP])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_VLAN_PCP

    if attrs.has_key(core.DL_SRC):
        v = convert_to_eaddr(attrs[core.DL_SRC])
        if v == None:
            print 'invalid ethernet addr'
            return None
        m.set_dl_src(v.octet)
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_SRC

    if attrs.has_key(core.DL_DST):
        v = convert_to_eaddr(attrs[core.DL_DST])
        if v == None:
            print 'invalid ethernet addr'
            return None
        m.set_dl_dst(v.octet)
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_DST

    if attrs.has_key(core.DL_TYPE):
        m.dl_type = htons(attrs[core.DL_TYPE])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_DL_TYPE

    if attrs.has_key(core.NW_SRC):
        v = convert_to_ipaddr(attrs[core.NW_SRC])
        if v == None:
            print 'invalid ip addr'
            return None
        m.nw_src = v
        num_entries += 1

        if attrs.has_key(core.NW_SRC_N_WILD):
            n_wild = attrs[core.NW_SRC_N_WILD]
            if n_wild > 31:
                wildcards |= openflow.OFPFW_NW_SRC_MASK
            elif n_wild >= 0:
                wildcards |= n_wild << openflow.OFPFW_NW_SRC_SHIFT
            else:
                print 'invalid nw_src wildcard bit count', n_wild
                return None
            num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_SRC_MASK

    if attrs.has_key(core.NW_DST):
        v = convert_to_ipaddr(attrs[core.NW_DST])
        if v == None:
            print 'invalid ip addr'
            return None
        m.nw_dst = v
        num_entries += 1

        if attrs.has_key(core.NW_DST_N_WILD):
            n_wild = attrs[core.NW_DST_N_WILD]
            if n_wild > 31:
                wildcards |= openflow.OFPFW_NW_DST_MASK
            elif n_wild >= 0:
                wildcards |= n_wild << openflow.OFPFW_NW_DST_SHIFT
            else:
                print 'invalid nw_dst wildcard bit count', n_wild
                return None
            num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_DST_MASK

    if attrs.has_key(core.NW_PROTO):
        m.nw_proto = attrs[core.NW_PROTO]
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_PROTO

    if attrs.has_key(core.NW_TOS):
        m.nw_proto = attrs[core.NW_TOS]
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_NW_TOS

    if attrs.has_key(core.TP_SRC):
        m.tp_src = htons(attrs[core.TP_SRC])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_TP_SRC

    if attrs.has_key(core.TP_DST):
        m.tp_dst = htons(attrs[core.TP_DST])
        num_entries += 1
    else:
        wildcards = wildcards | openflow.OFPFW_TP_DST

    if num_entries != len(attrs.keys()):
        print 'undefined flow attribute type in attrs', attrs
        return None

    m.wildcards = c_htonl(wildcards)
    return m