怎么修改下面的Python代码来实现奇偶性的通信?,python奇偶,这是具体的题目要求mod
怎么修改下面的Python代码来实现奇偶性的通信?,python奇偶,这是具体的题目要求mod
这是具体的题目要求
modify the application in order to implement a simple port-based VLAN. Separate the traffic between even and odd numbered ports - e.g. odd ports can only communicate with other odd ports, and even ports can only communicate with other even ports. However, you will have to take into consideration the following rules:
• Ports 1 and 2 should belong to both VLANs. This means that the hosts connected to port 1 and 2 should be able to ping all other hosts connected to the switch.
• Special attention should be paid to broadcast messages. When a host on the virtual network issues a broadcast, the message should only be seen by those who are a part of its VLAN. Consider a case where the OVS has 6 hosts connected; then the view of each VLAN would be as shown below in Figure 2.
• Note that 'actions' variable in the packet handling function is a 'list' data structure. Thus, it’s possible to associate multiple actions (i.e. output to multiple ports) with just a single rule.
• If the ‘actions’ list is empty (i.e. []), then that corresponds to an action to drop any packets that matches the flow.
这是具体代码:
def handle_packet_in(self, ev): msg = ev.msg datapath = msg.datapath ofproto = datapath.ofproto dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0) dpid = datapath.id #Switch ID self.mac2port.setdefault(dpid, {}) #Create new record for this switch #If it didn't exist before LOG.info("Src MAC: %s; Dest MAC: %s", haddr_to_str(src), haddr_to_str(dst)) self.mac2port[dpid][src] = msg.in_port #Save record of port number # associated with MAC address broadcast = (dst == mac.BROADCAST) or mac.is_multicast(dst) if broadcast: out_port = ofproto.OFPP_FLOOD LOG.info("broadcast frame,flood and install flow") else: if src != dst: # Fetch port number associated with destination MAC # Return None if no record exists out_port = self.mac2port[dpid].get(dst, None) if out_port == None: LOG.info("Output port not found") out_port = ofproto.OFPP_FLOOD else: self._drop_packet(msg) return actions = [datapath.ofproto_parser.OFPActionOutput (out_port)] LOG.info("Input port: %s; Output port: %s", msg.in_port, out_port) rule = nx_match.ClsRule() rule.set_in_port(msg.in_port) rule.set_dl_dst(dst) rule.set_dl_src(src) rule.set_nw_dscp(0) datapath.send_flow_mod( rule=rule, cookie=0, commend=ofproto.OFPFC_ADD, idle_timeout=60, hard_timeout=60, priority=ofproto.OFP_DEFAULT_PRIORITY, flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions) datapath.send_packet_out(msg.buffer_id, msg.in_port, actions)
编橙之家文章,
相关内容
- 使用flask+sqlite注册账号时报错table user has no column named
- 关于Python3中的stderr日志文件写入?,python3stderr,环境:
- Python3.5报错:获悉当前工作目录中的.py文件?,python3.5.
- g++编译加入-fPIC -shared参数后调用PyRun_SampleString段错误,
- 如何在Python中使用subprocess准备shell执行环境,pythonsub
- Flask 中 url for 不理解是什么意思.甚至不理解其作用,
- flask-sqlalchemy 如何查询关系表中的一个字段?,,class
- 如何在mac上用python批量将word文件转成txt文件,pythontx
- python 字符问题'utf8' codec can't decode byte 0xe6 in position 0,
- peewee postgres ArrayField 和JSONField怎么update数据,peeweepos
评论关闭