예제 #1
0
	def _get_ue_ul_of_rule(self, ue, path, anchor):
		"""
		Write the OpenFlow rules along the computed routing path 
		"""
		ofrs = {}
		try:
			# Forwarding based on destination MAC unicast addr	
			in_port = [self.switches[path[0].link.src.dpid].ap_conf.port.port_no]
			for p in path:
				for inp in in_port:
					out_port = p.link.src.port_no
					if inp == out_port:
						out_port = ofproto.OFPP_IN_PORT

					match = ofp_parser.OFPMatch(in_port = inp,
												eth_type = ether.ETH_TYPE_IPV6,
												ipv6_src = (':'.join(anchor.nw_prefix), ipv6_utils.ipv6_mask_from_cidr(anchor.nw_prefix_len)))
					actions = [ofp_parser.OFPActionSetField(eth_src = self.switches[p.link.src.dpid].hw_addr),
								ofp_parser.OFPActionSetField(eth_dst = self.switches[p.link.dst.dpid].hw_addr),
								ofp_parser.OFPActionOutput(out_port)]
					instructions = [ofp_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)]
				
					ofr = OFRule(self.switches[p.link.src.dpid], match, actions, instructions, table_id = OF_TABLE_UES)
					ofrs[ofr.key] = ofr

					in_port = [p.link.dst.port_no]

		except IndexError:
			self.logger.debug("Index error in _get_ue_ul_of_rule")

		return ofrs
예제 #2
0
	def _get_ue_dl_of_rule(self, ue, path, anchor):
		"""
		Write the OpenFlow rules along the computed routing path 
		"""
		ofrs = {}
		try:
			# Forwarding based on destination MAC unicast addr	
			in_port = [self.switches[path[0].link.src.dpid].gw_conf.port.port_no]
			for p in path:
				for inp in in_port:
					out_port = p.link.src.port_no
					if inp == out_port:
						out_port = ofproto.OFPP_IN_PORT
					
					for ipv6_addr in [ue.ipv6_addr, ipv6_utils.ipv6_global_from_mac(anchor.nw_prefix, anchor.nw_prefix_len, ue.hw_addr)]:
						match = ofp_parser.OFPMatch(in_port = inp,
													eth_type = ether.ETH_TYPE_IPV6,
													ipv6_dst = ipv6_addr)
						actions = [ofp_parser.OFPActionSetField(eth_src = self.switches[p.link.src.dpid].hw_addr),
									ofp_parser.OFPActionSetField(eth_dst = self.switches[p.link.dst.dpid].hw_addr),
									ofp_parser.OFPActionOutput(out_port)]
						instructions = [ofp_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)]
				
						ofr = OFRule(self.switches[p.link.src.dpid], match, actions, instructions, table_id = OF_TABLE_UES)
						ofrs[ofr.key] = ofr
			
						# ICMPv6 target	
						for icmpv6_type in [icmpv6.ND_NEIGHBOR_SOLICIT, icmpv6.ND_NEIGHBOR_ADVERT]:
							match = ofp_parser.OFPMatch(in_port = inp,
														eth_type = ether.ETH_TYPE_IPV6,
														ip_proto = inet.IPPROTO_ICMPV6,
														icmpv6_type = icmpv6_type,
														ipv6_nd_target = ipv6_addr)
							actions = [ofp_parser.OFPActionOutput(out_port)]
							instructions = [ofp_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)]
				
							ofr = OFRule(self.switches[p.link.src.dpid], match, actions, instructions, table_id = OF_TABLE_UES)
							ofrs[ofr.key] = ofr

				in_port = [p.link.dst.port_no]

			match = ofp_parser.OFPMatch(in_port = in_port[0],
										eth_type = ether.ETH_TYPE_IPV6,
										ipv6_dst = (':'.join(anchor.nw_prefix), ipv6_utils.ipv6_mask_from_cidr(anchor.nw_prefix_len)))
			actions = [ofp_parser.OFPActionSetField(eth_src = anchor.gw.hw_addr),
						ofp_parser.OFPActionSetField(eth_dst = ue.hw_addr),
						ofp_parser.OFPActionOutput(self.switches[path[-1].link.dst.dpid].ap_conf.port.port_no)]
			instructions = [ofp_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)]
			
			ofr = OFRule(self.switches[path[-1].link.dst.dpid], match, actions, instructions, table_id = OF_TABLE_UES)
			ofrs[ofr.key] = ofr

		except IndexError:
			self.logger.debug("Index error in _get_ue_dl_of_rule")

		return ofrs
예제 #3
0
    def _get_ue_ul_of_rule(self, ue, path, anchor):
        """
		Write the OpenFlow rules along the computed routing path 
		"""
        ofrs = {}
        try:
            # Forwarding based on destination MAC unicast addr
            in_port = [
                self.switches[path[0].link.src.dpid].ap_conf.port.port_no
            ]
            for p in path:
                for inp in in_port:
                    out_port = p.link.src.port_no
                    if inp == out_port:
                        out_port = ofproto.OFPP_IN_PORT

                    match = ofp_parser.OFPMatch(
                        in_port=inp,
                        eth_type=ether.ETH_TYPE_IPV6,
                        ipv6_src=(':'.join(anchor.nw_prefix),
                                  ipv6_utils.ipv6_mask_from_cidr(
                                      anchor.nw_prefix_len)))
                    actions = [
                        ofp_parser.OFPActionSetField(
                            eth_src=self.switches[p.link.src.dpid].hw_addr),
                        ofp_parser.OFPActionSetField(
                            eth_dst=self.switches[p.link.dst.dpid].hw_addr),
                        ofp_parser.OFPActionOutput(out_port)
                    ]
                    instructions = [
                        ofp_parser.OFPInstructionActions(
                            ofproto.OFPIT_APPLY_ACTIONS, actions)
                    ]

                    ofr = OFRule(self.switches[p.link.src.dpid],
                                 match,
                                 actions,
                                 instructions,
                                 table_id=OF_TABLE_UES)
                    ofrs[ofr.key] = ofr

                    in_port = [p.link.dst.port_no]

        except IndexError:
            self.logger.debug("Index error in _get_ue_ul_of_rule")

        return ofrs
예제 #4
0
    def _write_gw_rules(self, switch):
        """
		Initialiaze Gateway OpenFlow rules
		"""
        # Send unkown IP dst packets to the controller
        match = ofp_parser.OFPMatch(
            eth_dst=switch.hw_addr,
            eth_type=ether.ETH_TYPE_IPV6,
            ipv6_src=(':'.join(switch.gw_conf.nw_prefix),
                      ipv6_utils.ipv6_mask_from_cidr(
                          switch.gw_conf.nw_prefix_len)))
        actions = [ofp_parser.OFPActionOutput(ofproto.OFPP_CONTROLLER)]
        instructions = [
            ofp_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                             actions)
        ]
        req = EventWriteOFRule(
            OFRule(switch,
                   match,
                   actions,
                   instructions,
                   table_id=OF_TABLE_UNKNOWN))
        self.send_event(req.dst, req)
예제 #5
0
    def _get_ue_dl_of_rule(self, ue, path, anchor):
        """
		Write the OpenFlow rules along the computed routing path 
		"""
        ofrs = {}
        try:
            # Forwarding based on destination MAC unicast addr
            in_port = [
                self.switches[path[0].link.src.dpid].gw_conf.port.port_no
            ]
            for p in path:
                for inp in in_port:
                    out_port = p.link.src.port_no
                    if inp == out_port:
                        out_port = ofproto.OFPP_IN_PORT

                    for ipv6_addr in [
                            ue.ipv6_addr,
                            ipv6_utils.ipv6_global_from_mac(
                                anchor.nw_prefix, anchor.nw_prefix_len,
                                ue.hw_addr)
                    ]:
                        match = ofp_parser.OFPMatch(
                            in_port=inp,
                            eth_type=ether.ETH_TYPE_IPV6,
                            ipv6_dst=ipv6_addr)
                        actions = [
                            ofp_parser.OFPActionSetField(eth_src=self.switches[
                                p.link.src.dpid].hw_addr),
                            ofp_parser.OFPActionSetField(eth_dst=self.switches[
                                p.link.dst.dpid].hw_addr),
                            ofp_parser.OFPActionOutput(out_port)
                        ]
                        instructions = [
                            ofp_parser.OFPInstructionActions(
                                ofproto.OFPIT_APPLY_ACTIONS, actions)
                        ]

                        ofr = OFRule(self.switches[p.link.src.dpid],
                                     match,
                                     actions,
                                     instructions,
                                     table_id=OF_TABLE_UES)
                        ofrs[ofr.key] = ofr

                        # ICMPv6 target
                        for icmpv6_type in [
                                icmpv6.ND_NEIGHBOR_SOLICIT,
                                icmpv6.ND_NEIGHBOR_ADVERT
                        ]:
                            match = ofp_parser.OFPMatch(
                                in_port=inp,
                                eth_type=ether.ETH_TYPE_IPV6,
                                ip_proto=inet.IPPROTO_ICMPV6,
                                icmpv6_type=icmpv6_type,
                                ipv6_nd_target=ipv6_addr)
                            actions = [ofp_parser.OFPActionOutput(out_port)]
                            instructions = [
                                ofp_parser.OFPInstructionActions(
                                    ofproto.OFPIT_APPLY_ACTIONS, actions)
                            ]

                            ofr = OFRule(self.switches[p.link.src.dpid],
                                         match,
                                         actions,
                                         instructions,
                                         table_id=OF_TABLE_UES)
                            ofrs[ofr.key] = ofr

                in_port = [p.link.dst.port_no]

            match = ofp_parser.OFPMatch(
                in_port=in_port[0],
                eth_type=ether.ETH_TYPE_IPV6,
                ipv6_dst=(':'.join(anchor.nw_prefix),
                          ipv6_utils.ipv6_mask_from_cidr(
                              anchor.nw_prefix_len)))
            actions = [
                ofp_parser.OFPActionSetField(eth_src=anchor.gw.hw_addr),
                ofp_parser.OFPActionSetField(eth_dst=ue.hw_addr),
                ofp_parser.OFPActionOutput(
                    self.switches[path[-1].link.dst.dpid].ap_conf.port.port_no)
            ]
            instructions = [
                ofp_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                                 actions)
            ]

            ofr = OFRule(self.switches[path[-1].link.dst.dpid],
                         match,
                         actions,
                         instructions,
                         table_id=OF_TABLE_UES)
            ofrs[ofr.key] = ofr

        except IndexError:
            self.logger.debug("Index error in _get_ue_dl_of_rule")

        return ofrs