Example #1
0
	def switch_reactor(self, message, channel):
		import twink.ofp4.parse as ofp4p
		import twink.ofp4.build as ofp4b
		msg = ofp4p.parse(message)
		if msg.header.type==18 and msg.type==13:
			channel.send(ofp4b.ofp_multipart_reply(ofp4b.ofp_header(4, 19, None, msg.header.xid),
				13, 0, ()))
Example #2
0
def switch_proc(message, channel):
	msg = p.parse(message)
	if msg.header.type == OFPT_FEATURES_REQUEST:
		channel.send(b.ofp_switch_features(b.ofp_header(4, OFPT_FEATURES_REPLY, 0, msg.header.xid), 1, 2, 3, 0, 0xF))
	elif msg.header.type == OFPT_GET_CONFIG_REQUEST:
		channel.send(b.ofp_switch_config(b.ofp_header(4, OFPT_GET_CONFIG_REPLY, 0, msg.header.xid), 0, 0xffe5))
	elif msg.header.type == OFPT_MULTIPART_REQUEST:
		if msg.type == OFPMP_FLOW:
			channel.send(b.ofp_multipart_reply(b.ofp_header(4, OFPT_MULTIPART_REPLY, 0, msg.header.xid),
				msg.type, 0, [
					b.ofp_flow_stats(None, 0, 10, 20, 30, 40, 50, 0, 1, 2, 3,
						b.ofp_match(None, None, "".join([
							oxm.build(None, oxm.OXM_OF_IN_PORT, None, None, 222),
							oxm.build(None, oxm.OXM_OF_ETH_SRC, None, None, binascii.a2b_hex("00112233"))])),
						[b.ofp_instruction_actions(OFPIT_APPLY_ACTIONS, None, [
							b.ofp_action_output(None, None, 1111, OFPCML_MAX)]),
						]),]))
Example #3
0
def switch_proc(message, ofchannel):

    msg = p.parse(message)

    # TODO: Acquire lock

    if msg.header.type == OFPT_FEATURES_REQUEST:
        channel.send(b.ofp_switch_features(b.ofp_header(4, OFPT_FEATURES_REPLY, 0, msg.header.xid), 1, 2, 3, 0, 0xF))

    elif msg.header.type == OFPT_GET_CONFIG_REQUEST:
        channel.send(b.ofp_switch_config(b.ofp_header(4, OFPT_GET_CONFIG_REPLY, 0, msg.header.xid), 0, 0xffe5))

    elif msg.header.type == OFPT_ROLE_REQUEST:
        channel.send(b.ofp_role_request(b.ofp_header(4, OFPT_ROLE_REPLY, 0, msg.header.xid), msg.role, msg.generation_id))

    elif msg.header.type == OFPT_FLOW_MOD:
        if msg.cookie not in flows:
            flows[msg.cookie] = msg
        else:
            print "I already have this FlowMod: Cookie", \
                msg.cookie, oxm.parse_list(flows[msg.cookie].match), (flows[msg.cookie].instructions)

    elif msg.header.type == OFPT_MULTIPART_REQUEST:
        if msg.type == OFPMP_FLOW:
            channel.send(b.ofp_multipart_reply(b.ofp_header(4, OFPT_MULTIPART_REPLY, 0, msg.header.xid),
                         msg.type, 0, ["".join(b.ofp_flow_stats(None, f.table_id, 1, 2, f.priority,
                                                                f.idle_timeout, f.hard_timeout, f.flags, f.cookie, 0, 0,
                                                                f.match, f.instructions)
                                               for f in flows.itervalues())]))
        elif msg.type == OFPMP_PORT_DESC:
            channel.send(b.ofp_multipart_reply(b.ofp_header(4, OFPT_MULTIPART_REPLY, 0, msg.header.xid),
                         msg.type, 0, ["".join(b.ofp_port(ofp.port_no, ofp.hw_addr, ofp.name, ofp.config, ofp.state,
                                                          ofp.curr, ofp.advertised, ofp.supported, ofp.peer, ofp.curr_speed, ofp.max_speed)
                                               for ofp in of_ports.itervalues())]))
        elif msg.type == OFPMP_DESC:
            channel.send(b.ofp_multipart_reply(b.ofp_header(4, OFPT_MULTIPART_REPLY, 0, msg.header.xid),
                         msg.type, 0, 
                         b.ofp_desc("UC Berkeley", "Intel Xeon", "BESS", "commit-6e343", None)))

    elif msg.header.type ==  OFPT_PACKET_OUT:
        index = msg.actions[0].port
        print "Packet out OF Port %d, Len:%d" % (index, len(msg.data))
        sock = of_ports[index].pkt_inout_socket
        if sock is not None:
            sent = sock.send(msg.data)
            if sent != len(msg.data):
                print "Incomplete Transmission Sent:%d, Len:%d" % (sent, len(msg.data))
        else:
            print "Packet out OF Port %d, Len:%d. Failed - Null socket" % (index, len(msg.data))

    elif msg.header.type == OFPT_HELLO:
        pass

    elif msg.header.type == OFPT_SET_CONFIG:
        pass

    elif msg.header.type == OFPT_BARRIER_REQUEST:
        pass

    else:
        print msg
        assert 0