def connect(ip, port=6653, daemon=True, ofp=loxi.of14):
"""
Actively connect to a switch
"""
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
soc.connect((ip, port))
soc.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
cxn = Connection(soc)
cxn.daemon = daemon
cxn.logger.debug("Connected to %s:%d", ip, port)
cxn.start()
cxn.send(ofp.message.hello())
if not cxn.recv(lambda msg: msg.type == ofp.OFPT_HELLO):
raise Exception("Did not receive HELLO")
return cxn
评论列表
文章目录