Exemplo n.º 1
0
def createAction(outputIntfs=None,
                 ethSrc=None,
                 ethDst=None,
                 ipSrc=None,
                 ipDst=None):
    action = eossdk.FlowAction()
    actionSet = eossdk.FlowActionSet()
    if outputIntfs is not None:
        # Until we have correct swig support for std::set,
        # need to add each interface individually
        actionSet.set_output_intfs_is(True)
        action.output_intfs_is(tuple([intfId for intfId in outputIntfs]))
    if ethSrc is not None:
        actionSet.set_eth_src_is(True)
        newEthSrc = eossdk.EthAddr(ethSrc)
        action.eth_src_is(newEthSrc)
    if ethDst is not None:
        actionSet.set_eth_dst_is(True)
        newEthDst = eossdk.EthAddr(ethDst)
        action.eth_dst_is(newEthDst)
    if ipSrc is not None:
        actionSet.set_ip_src_is(True)
        newIpSrc = eossdk.IpAddr(ipSrc)
        action.ip_src_is(newIpSrc)
    if ipDst is not None:
        actionSet.set_ip_dst_is(True)
        newIpDst = eossdk.IpAddr(ipDst)
        action.ip_dst_is(newIpDst)
    action.action_set_is(actionSet)
    return action
Exemplo n.º 2
0
def createMatch(inputIntfs=None,
                ethSrc=None,
                ethSrcMask="ff:ff:ff:ff:ff:ff",
                ethDst=None,
                ethDstMask="ff:ff:ff:ff:ff:ff",
                ethType=None,
                ipSrc=None,
                ipSrcMask="255.255.255.255",
                ipDst=None,
                ipDstMask="255.255.255.255"):
    match = eossdk.FlowMatch()
    matchFieldSet = eossdk.FlowMatchFieldSet()
    if inputIntfs is not None:
        # Until we have correct swig support for std::set,
        # need to add each interface individually
        matchFieldSet.input_intfs_is(True)
        match.input_intfs_is(tuple([intfId for intfId in inputIntfs]))
    if ethSrc is not None:
        matchFieldSet.eth_src_is(True)
        ethSrc = eossdk.EthAddr(ethSrc)
        ethSrcMask = eossdk.EthAddr(ethSrcMask)
        match.eth_src_is(ethSrc, ethSrcMask)
    if ethDst is not None:
        matchFieldSet.eth_dst_is(True)
        ethDst = eossdk.EthAddr(ethDst)
        ethDstMask = eossdk.EthAddr(ethDstMask)
        match.eth_dst_is(ethDst, ethDstMask)
    if ethType is not None:
        matchFieldSet.eth_type_is(True)
        match.eth_type_is(ethType)
    if ipSrc is not None:
        matchFieldSet.ip_src_is(True)
        ipSrc = eossdk.IpAddr(ipSrc)
        ipSrcMask = eossdk.IpAddr(ipSrcMask)
        match.ip_src_is(ipSrc, ipSrcMask)
    if ipDst is not None:
        matchFieldSet.ip_dst_is(True)
        ipDst = eossdk.IpAddr(ipDst)
        ipDstMask = eossdk.IpAddr(ipDstMask)
        match.ip_dst_is(ipDst, ipDstMask)
    match.match_field_set_is(matchFieldSet)
    return match
Exemplo n.º 3
0
    def resolve_egress_tunnel(self, tunnel):
        self.tracer.trace8("Resolve the nexthop IP %s to an ethernet address" %
                           tunnel.nexthop_ip)
        neighbor_key = eossdk.NeighborKey(eossdk.IpAddr(tunnel.nexthop_ip),
                                          eossdk.IntfId())
        neighbor_entry = self.neighbor_table_mgr.neighbor_entry_status(
            neighbor_key)
        if neighbor_entry == eossdk.NeighborEntry():
            self.tracer.trace8("Checking static ARP entries")
            neighbor_entry = self.neighbor_table_mgr.neighbor_entry(
                neighbor_key)
        if neighbor_entry == eossdk.NeighborEntry():
            self.tracer.trace0("IP address %r has no ARP entry" %
                               tunnel.nexthop_ip)
            assert False, "Unlearned nexthop IP %s" % tunnel.nexthop_ip
        nexthop_eth_addr = neighbor_entry.eth_addr()
        self.tracer.trace5("IP %s lives on %s" %
                           (tunnel.nexthop_ip, nexthop_eth_addr.to_string()))
        tunnel.nexthop_eth_addr = nexthop_eth_addr.to_string()

        self.tracer.trace8("Now resolving that MAC entry to an interface.")
        # TODO: Is this necessary if we send it out of the "fabric"
        # interface?
        vlan_id = 1
        mac_entry = self.mac_table_mgr.mac_entry(vlan_id, nexthop_eth_addr)
        if mac_entry.intf() == eossdk.IntfId():
            self.tracer.trace0("Mac entry %r not on any interface" %
                               tunnel.nexthop_eth_addr)
            assert False, "Unlearned nexthop MAC %s" % tunnel.nexthop_eth_addr
        intf = mac_entry.intf().to_string()
        # Convert the interface names to the kernel interface names
        intf = intf.replace("Ethernet", "et")
        intf = intf.replace("Port-Channel", "po")
        self.tracer.trace5("MAC entry %s is learned on inteface %r" %
                           (tunnel.nexthop_eth_addr, intf))
        tunnel.egress_intf = intf

        self.tracer.trace8("Looking up that interface's MAC address")
        egress_eth_addr = self.eth_intf_mgr.eth_addr(mac_entry.intf())
        if egress_eth_addr == eossdk.EthAddr():
            assert False, "Interface %s has no MAC address" % intf
        self.tracer.trace5("Intf %s has MAC address %s" %
                           (intf, egress_eth_addr.to_string()))
        tunnel.egress_intf_eth_addr = egress_eth_addr.to_string()