Example #1
0
    def _generate_links(self, lnk):
        lnk_src_port = lnk["source"]["source-tp"]
        lnk_src_node = lnk["source"]["source-node"]
        lnk_dst_port = lnk["destination"]["dest-tp"]
        lnk_dst_node = lnk["destination"]["dest-node"]

        if lnk_src_node.find("openflow") >= 0 and lnk_dst_node.find(
                "openflow") >= 0:
            lnk_id = self._get_flow_id(lnk_src_node, lnk_dst_node)
            rev_lnk_id = self._get_flow_id(lnk_dst_node, lnk_src_node)
        else:
            lnk_id = lnk["link-id"]
            src, splitor, dst = lnk["link-id"].partition("/")
            rev_lnk_id = "/".join([dst, src])

        of_link = OfLink()
        of_link.set_attributes(link_id=lnk_id,
                               srcnode=lnk_src_node,
                               dstnode=lnk_dst_node,
                               srcport=lnk_src_port,
                               dstport=lnk_dst_port)
        rvs_link = OfLink()
        rvs_link.set_attributes(link_id=rev_lnk_id,
                                srcnode=lnk_dst_node,
                                dstnode=lnk_src_node,
                                srcport=lnk_dst_port,
                                dstport=lnk_src_port)
        return of_link, rvs_link
Example #2
0
def test_dbservice():
    print("Try to test dbServices")
    db_svc = DbServices(session)
    swnode = OFNodeBase()
    swnode.set_attributes("openflow:1","s1",const.SWITCH,"aa:bb:cc:dd:ee:ff")
    hostnode = OFNodeBase()
    hostnode.set_attributes("openflow:1:3","10.1.1.3",const.HOST,"bb:bb:cc:dd:ee:ff")
    db_svc.add_ofnode(swnode)
    print( len(db_svc.list_ofnodes()) == 1)
    db_svc.add_ofnode(hostnode)
    print( len(db_svc.list_ofnodes()) == 2)
    fwnode = OFNodeBase()
    fwnode.set_attributes("openflow:2","s2",const.FIREWALL,"aa:cc:cc:dd:ee:ff")
    lbnode = OFNodeBase()
    lbnode.set_attributes("openflow:3","s3",const.LOADBALANCE,"aa:dd:cc:dd:ee:ff")
    db_svc.add_ofnode(fwnode)
    db_svc.add_ofnode(lbnode)
    print( len(db_svc.list_ofnodes()) == 4)
    nv_link1 = OfLink()
    nv_link1.set_attributes(link_id="openflow:1:2",srcnode="openflow:1", dstnode="openflow:2", srcport="openflow:1:1", dstport="openflow:2:1")
    nv_link2 = OfLink()
    nv_link2.set_attributes(link_id="openflow:1:3",srcnode="openflow:1", dstnode="openflow:3", srcport="openflow:1:2", dstport="openflow:3:1")
    db_svc.add_oflink(nv_link1)
    db_svc.add_oflink(nv_link2)
    print( len(db_svc.list_oflink()) == 2)

    sc_template = SCTemplate()
    sc_template.set_attributes("template1", "firewall:loadbalance")
    db_svc.add_sctplt(sc_template)
    print(len(db_svc.list_sctplt()) == 1)

    sc_instance = SCInstance()
    sc_instance.set_attributes("tcp", "80", sc_template.instid,id="sc-template-1")
    db_svc.add_scinstance(sc_instance)
    print(len(db_svc.list_scinstance()) == 1)

    sc_app = SCApp()
    sc_app.set_attributes(hostnode.nodeid, sc_instance.instid)
    db_svc.add_scapp(sc_app)
    print(len(db_svc.list_scapp()) == 1)

    db_svc.mod_ofnode_type(lbnode,const.NAT)
    nat_node = db_svc.get_ofnode_by_type(const.NAT)
    print(nat_node.nodeid == lbnode.nodeid)
    def _generate_links(self, lnk):
        lnk_src_port = lnk["source"]["source-tp"]
        lnk_src_node = lnk["source"]["source-node"]
        lnk_dst_port = lnk["destination"]["dest-tp"]
        lnk_dst_node = lnk["destination"]["dest-node"]

        if lnk_src_node.find("openflow") >= 0 and lnk_dst_node.find("openflow")>=0 :
            lnk_id = self._get_flow_id(lnk_src_node, lnk_dst_node)
            rev_lnk_id = self._get_flow_id(lnk_dst_node, lnk_src_node)
        else:
            lnk_id = lnk["link-id"]
            src, splitor, dst = lnk["link-id"].partition("/")
            rev_lnk_id = "/".join([dst, src])

        of_link = OfLink()
        of_link.set_attributes(link_id=lnk_id,srcnode=lnk_src_node,dstnode=lnk_dst_node,srcport=lnk_src_port, dstport=lnk_dst_port)
        rvs_link = OfLink()
        rvs_link.set_attributes(link_id=rev_lnk_id,srcnode=lnk_dst_node,dstnode=lnk_src_node,srcport=lnk_dst_port, dstport=lnk_src_port)
        return of_link, rvs_link