public override void features_reply() { for(int i=0; i<phy_port_list.Count; i++) { if (phy_port_list[i].name =="tapdevice") { tap_port = phy_port_list[i].port_no; } } }
public void learning(byte[] addr, ofp_port port) { if (list.Exists(e => mac_compare(addr, e.mac_addr))) { Entry entry = list.Find(e => mac_compare(addr, e.mac_addr)); //mac address with different port number -> update to new port number if ( entry.port != port ) { //list.Remove(e => e.mac_addr.Equals(addr)); list.Remove(entry); //Entry entry = new Entry(); entry.port = port; list.Add(entry); } } else { Entry entry = new Entry(); entry.mac_addr = addr; entry.port = port; list.Add(entry); } show(); }
public void insert(byte[] addr, ofp_port port) { Entry entry = new Entry(); entry.mac_addr = addr; entry.port = port; list.Add(entry); }
public byte[] ofp_flow_mod(uint32_t xid, byte[] match, uint64_t cookie, ofp_flow_mod_command command, uint16_t idle_timeout, uint16_t hard_timeout, uint16_t priority, uint32_t buffer_id, ofp_port out_port, ofp_flow_mod_flags flags, byte[] actions) { if (match.Length != 40) { return null; } byte[] ret = new byte[72+actions.Length]; ret[0] = ofp_version; ret[1] = (uint8_t) ofp_type.OFPT_FLOW_MOD; uint16_to_bytes((uint16_t) (72 + actions.Length), ref ret, 2); uint32_to_bytes(xid, ref ret, 4); Array.Copy(match, 0, ret, 8, 40); uint64_to_bytes(cookie, ref ret, 48); uint16_to_bytes((uint16_t) command, ref ret, 56); uint16_to_bytes(idle_timeout, ref ret, 58); uint16_to_bytes(hard_timeout, ref ret, 60); uint16_to_bytes(priority, ref ret, 62); uint32_to_bytes(buffer_id, ref ret, 64); uint16_to_bytes((uint16_t) out_port, ref ret, 68); uint16_to_bytes((uint16_t) flags, ref ret, 70); Array.Copy(actions, 0, ret, 72, actions.Length); return ret; }
public byte[] ofp_match(uint32_t wildcards, ofp_port in_port, byte[] dl_src, byte[] dl_dst, uint16_t dl_vlan, uint8_t dl_vlan_pcp, Eth_type dl_type, uint8_t nw_tos, uint8_t nw_proto, IPAddress nw_src, IPAddress nw_dst, uint16_t tp_src, uint16_t tp_dst) { byte[] ret = new byte[40]; uint32_to_bytes(wildcards, ref ret, 0); uint16_to_bytes((uint16_t) in_port, ref ret, 4); Array.Copy(dl_src, 0, ret, 6, OFP_ETH_ALEN); Array.Copy(dl_dst, 0, ret, 12, OFP_ETH_ALEN); uint16_to_bytes(dl_vlan, ref ret, 18); ret[20]=dl_vlan_pcp; uint16_to_bytes((uint16_t) dl_type, ref ret, 22); ret[24] = nw_tos; ret[25] = nw_proto; //uint32_to_bytes(nw_src, ref ret, 28); //uint32_to_bytes(nw_dst, ref ret, 32); Array.Copy(nw_src.GetAddressBytes(), 0, ret, 28, nw_src.GetAddressBytes().Length); Array.Copy(nw_dst.GetAddressBytes(), 0, ret, 32, nw_dst.GetAddressBytes().Length); uint16_to_bytes(tp_src, ref ret, 36); uint16_to_bytes(tp_dst, ref ret, 38); return ret; }
public byte[] ofp_packet_out(uint32_t xid, uint32_t buffer_id, ofp_port in_port, byte[] actions) { byte[] ret = new byte[16+actions.Length]; ret[0] = ofp_version; ret[1] = (uint8_t) ofp_type.OFPT_PACKET_OUT; uint16_to_bytes((uint16_t) (16 + actions.Length), ref ret, 2); uint32_to_bytes(xid, ref ret, 4); uint32_to_bytes(buffer_id, ref ret, 8); uint16_to_bytes((uint16_t) in_port, ref ret, 12); uint16_to_bytes((uint16_t) actions.Length, ref ret, 14); Array.Copy(actions, 0, ret, 16, actions.Length); return ret; }
protected byte[] ofp_action_output(ofp_port port) { byte[] ret = new byte[8]; uint16_to_bytes((uint16_t) ofp_action_type.OFPAT_OUTPUT, ref ret, 0); uint16_to_bytes((uint16_t) 8, ref ret, 2); uint16_to_bytes((uint16_t) port, ref ret, 4); uint16_to_bytes((uint16_t) 0, ref ret, 6); return ret; }
public ofp_port_features peer; /* Features advertised by peer. */ public ofp_phy_port(ref byte[] msg, int offset) { port_no = (ofp_port) byte_reorder16(msg, offset); hw_addr = new uint8_t[OFP_ETH_ALEN]; Array.Copy(msg, offset+2, hw_addr, 0, OFP_ETH_ALEN); string s = Encoding.Default.GetString(msg, offset+8, OFP_MAX_PORT_NAME_LEN); name = s.Substring(0, s.IndexOf((char) 0)); config = (ofp_port_config) byte_reorder32(msg, offset+24); state = (ofp_port_state) byte_reorder32(msg, offset+28); curr = (ofp_port_features) byte_reorder32(msg, offset+32); advertised = (ofp_port_features) byte_reorder32(msg, offset+36); supported = (ofp_port_features) byte_reorder32(msg, offset+40); peer = (ofp_port_features) byte_reorder32(msg, offset+44); }
public Flow(ref byte[] header, ref byte[] msg, Logger logger) { ofp_version = header[0]; type = (ofp_type) header[1]; length = byte_reorder16(header, 2); xid = byte_reorder32(header, 4); wildcards = 0; logger.WriteLine("-----------------------------------------------FLOW--------------------------------------------------------"); logger.WriteLine("FLOW ofp_header version:{0} type:{1} length:{2} xid:{3}", ofp_version, type, length, xid); switch(type) { case ofp_type.OFPT_HELLO: logger.WriteLine("-----------------------------------------------------------------------------------------------------------"); return; case ofp_type.OFPT_ERROR: ofp_error_t = (ofp_error_type) byte_reorder16(msg, 0); ofp_error_code = byte_reorder16(msg, 2); logger.WriteLine("FLOW OFPT_ERROR | type:{0} code:{1} ", ofp_error_t, ofp_error_code); logger.WriteLine("-----------------------------------------------------------------------------------------------------------"); return; case ofp_type.OFPT_ECHO_REQUEST: logger.WriteLine("-----------------------------------------------------------------------------------------------------------"); return; case ofp_type.OFPT_PACKET_IN: buffer_id = byte_reorder32(msg, 0); total_len = byte_reorder16(msg, 4); in_port = (ofp_port) byte_reorder16(msg, 6); reason = (ofp_packet_in_reason) msg[8]; logger.WriteLine("buffer_id:{0:x} total_len:{1} in_port:{2} reason:{3}", buffer_id, total_len, in_port, reason); logger.WriteLine(""); // Link Layer l2_offset = 10; Array.Copy(msg, l2_offset, dl_dst, 0, OFP_ETH_ALEN); Array.Copy(msg, l2_offset+OFP_ETH_ALEN, dl_src, 0, OFP_ETH_ALEN); //802.11Q and VLAN tag is not yet implemented if (byte_reorder16(msg, l2_offset+2*OFP_ETH_ALEN) == (uint16_t) Eth_type.ETH_TYPE_VLAN ) { dl_vlan = (uint16_t) (BitConverter.ToUInt16(msg, l2_offset+2*OFP_ETH_ALEN+2) & 0x0fff); dl_vlan_pcp = (uint8_t) (BitConverter.ToUInt16(msg, l2_offset+2*OFP_ETH_ALEN+2) >> 13); eth_type = (Eth_type) byte_reorder16(msg, l2_offset+2*OFP_ETH_ALEN+4); l3_offset = l2_offset+2*OFP_ETH_ALEN+6; } else { eth_type = (Eth_type) byte_reorder16(msg, l2_offset+2*OFP_ETH_ALEN); l3_offset = l2_offset+2*OFP_ETH_ALEN+2; } logger.WriteLine("dl_src:{0:X} dl_dst:{1:X}", BitConverter.ToString(dl_src), BitConverter.ToString(dl_dst)); logger.WriteLine("eth_type:{0}", eth_type); switch (eth_type) { case Eth_type.ETH_TYPE_RARP: break; case Eth_type.ETH_TYPE_ARP: this.wildcards = ofp_flow_wildcards.OFPFW_TP_SRC | ofp_flow_wildcards.OFPFW_TP_DST | ofp_flow_wildcards.OFPFW_DL_VLAN | ofp_flow_wildcards.OFPFW_DL_VLAN_PCP; if ( byte_reorder16(msg, l3_offset) == 1 && byte_reorder16(msg, l3_offset+2) == (uint16_t) Eth_type.ETH_TYPE_IP && msg[l3_offset+4] == OFP_ETH_ALEN && msg[l3_offset+5] == 4 && byte_reorder16(msg, l3_offset+6) <= 0xff) { //referred to flow.c flow_extract nw_proto = byte_reorder16(msg, l3_offset+6); //nw_src = new IPAddress(byte_reorder32(msg, l3_offset+14)); //nw_dst = new IPAddress(byte_reorder32(msg, l3_offset+24)); //nw_src = new IPAddress(msg.Skip(l3_offset+14).Take(4).ToArray()); //nw_dst = new IPAddress(msg.Skip(l3_offset+24).Take(4).ToArray()); nw_src = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+14)); nw_dst = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+24)); Array.Copy(msg, l3_offset+8, arp_sha, 0, OFP_ETH_ALEN); Array.Copy(msg, l3_offset+18, arp_tha, 0, OFP_ETH_ALEN); } logger.WriteLine("nw_proto:{0:X} nw_src:{1:X} nw_dst:{2:X} arp_sha:{3:X} arp_tha", nw_proto, nw_src, nw_dst, arp_sha, arp_tha); break; case Eth_type.ETH_TYPE_IP: this.wildcards = ofp_flow_wildcards.OFPFW_DL_VLAN | ofp_flow_wildcards.OFPFW_DL_VLAN_PCP; //Extract_IP_ETH_HEADER(ref msg); ipv4_version = (byte) (msg[l3_offset] >> 4); ihl = (byte) (msg[l3_offset] & 0x0f); nw_tos = (byte) (msg[l3_offset+1] >> 2); total_length = byte_reorder16(msg, l3_offset+2); nw_proto = msg[l3_offset+9]; //TCP/UDP //nw_src = new IPAddress(byte_reorder32(msg, l3_offset+12)); //nw_dst = new IPAddress(byte_reorder32(msg, l3_offset+16)); //nw_src = new IPAddress(msg.Skip(l3_offset+12).Take(4)); //nw_dst = new IPAddress(msg.Skip(l3_offset+16).Take(4)); nw_src = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+12)); nw_dst = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+16)); logger.WriteLine("version:{0} ihl:{1}", ipv4_version, ihl); logger.WriteLine("nw_tos(Type of Service):{0} total_length:{1} protocol:{2}", nw_tos, total_length, nw_proto); if (ihl > 5) { l4_offset = l3_offset + 24; } else { l4_offset = l3_offset + 20; } logger.WriteLine("l3_offset:{0}, l4_offset:{1}", l3_offset, l4_offset); tp_src = byte_reorder16(msg, l4_offset); tp_dst = byte_reorder16(msg, l4_offset+2); logger.WriteLine("protocol:{0:X} ", nw_proto); logger.WriteLine("nw_src:{0} nw_dst:{1} tp_src:{2} tp_dst:{3}", nw_src.ToString(), nw_dst.ToString(), tp_src, tp_dst); break; case Eth_type.ETH_TYPE_IPV6: logger.WriteLine("Eth_type.ETH_TYPE_IPV6:"); break; case (Eth_type) 44: logger.WriteLine("ethernet type 44 0x2c ipv6 framenet "); break; default: logger.WriteLine("FATAL: UNKNOWN ETHERNET HEADER TYPE"); Environment.Exit(1); break; } break; default: logger.WriteLine("Unknown packet from switch"); Environment.Exit(1); break; } logger.WriteLine("-----------------------------------------------------------------------------------------------------------"); }