[P4-dev] Doubts Regarding use of Register

Stern, David J CIV DISA ID (US) david.j.stern.civ at mail.mil
Thu Aug 20 15:03:49 EDT 2015


Antonin-
I was having the same issue but it looks like a different reason.

edias at EDIAS-UBUNTU-64:/tmp$ cat p4ns.s1.log

PD server address is 127.0.0.1:22222

P4 Program:  simple_router

Starting RPC server on port 22222

No p4nsdb address specified, using 127.0.0.1:6379

Could not connect to P4NS DB


===========================

Also, I updated to the latest from git and started to get this as well.

edias at EDIAS-UBUNTU-64:~/p4factory/targets/basic_routing$ sudo python run_tests.py --test-dir of-tests/tests/

[sudo] password for edias: 

/home/edias/p4factory/targets/basic_routing/of-tests/pd_thrift

[]

WARNING: No route found for IPv6 destination :: (no default route?)

VXLAN enabled

ERSPAN enabled

Traceback (most recent call last):

  File "/home/edias/p4factory/targets/basic_routing/../../submodules/oft-infra/oft", line 449, in <module>

    import oftest.testutils

  File "/home/edias/p4factory/submodules/oft-infra/src/python/oftest/testutils.py", line 7, in <module>

    import packet as scapy

  File "/home/edias/p4factory/submodules/oft-infra/src/python/oftest/packet.py", line 48, in <module>

    ERSPAN_III = scapy.contrib.erspan.ERSPAN_III

AttributeError: 'module' object has no attribute 'ERSPAN_III'





-----Original Message-----
From: P4-dev [mailto:p4-dev-bounces at p4.org] On Behalf Of Antonin Bas
Sent: Tuesday, August 18, 2015 5:21 PM
To: Swaroop Thool
Cc: p4-dev at p4.org
Subject: Re: [P4-dev] Doubts Regarding use of Register

Hi Swaroop,


Thanks for reporting this behavior. Could you confirm that this happens when you run "./run_demo.bash" in p4factory/targets/simple_router?

When you run this script, a log file should be generated under /tmp/: p4ns.s1.log. Could you send it to me?

It may be some bad state after a switch instance was not killed properly. You may want to run the following 3 commands and see if it solves it:

- redis-cli FLUSHALL

- sudo killall behavioral-model

- sudo mn -c


Thanks,


Antonin


On Tue, Aug 18, 2015 at 1:12 PM, Swaroop Thool <swaroopthool1991 at outlook.com> wrote:



	Hi Antonin,
	
	1) When I try to run demo of simple_router as stated under integrating with mininet: <https://github.com/p4lang/p4factory> <https://github.com/p4lang/p4factory> <https://github.com/p4lang/p4factory> <https://github.com/p4lang/p4factory> <https://github.com/p4lang/p4factory> https://github.com/p4lang/p4factory  
	 I get thrift.transport.TTransport.TTransportException: Could not connect to localhost:22222 . Also when I ping under mininet suddenly I get Disconnected: Ethernet Network message . I was only able to run this demo once and now its not going the same way. 
	
	
	2) Same message : Could not connect to localhost:22222 occurs when I try to start CLI for simple_router by below command inside targets/simple_router$ because I want to see table contents in another terminal: 
	
	python ../../cli/pd_cli.py -p simple_router -i p4_pd_rpc.simple_router -s of-tests/pd_thrift:../../submodules/oft-infra -c localhost:22222
	
	This may be because I have not run the above question 1.
	
	3) I want to check value updated for my register whether its right or not? Which is the best way to do that? Is that through API for table or have another API? 
	
	
	Thanks,
	Swaroop
	
	
	
________________________________

	Date: Thu, 13 Aug 2015 13:06:30 -0700

	Subject: Re: [P4-dev] Doubts Regarding use of Register
	From: antonin at barefootnetworks.com
	To: swaroopthool1991 at outlook.com
	CC: p4-dev at p4.org
	
	
	The locations have to come from somewhere. I don't see how you can do this without a table that looks like this:
	
	
	table flow_locations {
	
	  reads {
	
	    ipv4.dstAddr: exact;
	    ...
	  }
	
	  actions {
	
	    set_locations;
	
	    drop;
	  }
	}
	
	
	action set_locations(locA, locB, locC) {
	
	  modify_field(metaA.location, locA);
	  ...
	
	  // why not write to the registers here?
	
	}
	
	
	This table effectively maps flows to your register locations. Now maybe at some point, while processing a flow you need to retrieve the register values for another (previous) flow. In this case you need to have a second table like this one:
	
	
	table retrieve_flow_locations {
	
	  reads {
	
	    flow_meta.ipv4_dstAddr: exact;
	    ...
	  }
	
	  actions {
	
	    set_locations;
	
	    no_op;
	  }
	}
	
	
	Now of course you need to populate flow_meta.ipv4_dstAddr before applying this table (you can see flow_meta as your flow lookup key).
	
	The 2 tables (flow_locations and retrieve_flow_locations) are exactly the same in content (populated by you through the control plane). However they have to be 2 different P4 tables because 1) P4 does not let you apply the same table with a different key 2) our compiler rejects multiple invocations of the same table.
	
	
	Personally I find the above a little bit convoluted. But that's the best I can do. I don't really understand to what end you need to retrieve flow information for a given flow while you are processing a different flow.
	
	
	If all you are concerned about is making sure that packets belonging to the same flow always map to the same register indices, then it is pretty simple and pretty common, and you only need the first table (ignore the second table, retrieve_flow_locations).
	
	
	
	Now for your second question:
	
	You are running this command from the wrong directory. This command works specifically for the simple_router target and is supposed to run from targets/simple_router. If you have a target called AAA running and you want to connect to the CLI, you should go to targets/AAA and use the following:
	
	python ../../cli/pd_cli.py -p AAA -i p4_pd_rpc.AAA -s of-tests/pd_thrift:../../submodules/oft-infra -c localhost:22222
	
	(the port value is likely to be different, most likely 9090)
	
	
	Best,
	
	
	Antonin
	

	On Thu, Aug 13, 2015 at 8:48 AM, Swaroop Thool <swaroopthool1991 at outlook.com> wrote:
	

		Hi Antonin,
		
		Thank for your reply and sorry for my unclear question and annoying you as I am new in p4.
		
		I have:
		
		register r1 {  // THERE ARE 3 SUCH ARRAYS R1,R2,R3
		    width : 16;
		    instance_count : 500;   //single array of size 500 
		}
		
		I am considering array r1 of register of size 500. And there are total 3 such arrays say, r1,r2,r3.
		If I store 3 different values corresponding to 1st input (like 1st IP address) at location r1[10], r2[20], r3[30] using metadata fields (manipulation/transfer) where, my metadata is like temporary structure having fields as location and value as:
		
		header_type temp_metadata_t {  //THERE ARE 3 INSTANCES OF THIS FOR EACH R1, R2, R3
		  fields{     
		      location : 16;
		      value : 10; }
		}
		
		Again storing 3 different values corresponding to 2nd input (like 2nd IP address) at location r1[50], r2[60], r3[70] and so on for different number of inputs. Now I want to know what is the value at location "r1[10], r2[20], r3[30] " which should be corresponding to same input as stated above(here its 1st input). As I am using temp_metadata_t for value and location manipulation which puts my values in r1,r2,r3 and gets refreshed with new one as I proceed further. I dont have record to get values from location r1[10], r2[20], r3[30] belonging to 1st input. 
		Can I create table with run-time entries for this 3 values combination and use something like pointer? I dont know how to do this.
		
		Also, how to view table entries? I tried the below to start CLI  
		
		: ~/p4factory/cli$ ./pd_cli.py -p simple_router -s of-tests/pd_thrift:../../submodules/oft-infra -c localhost:22222
		
		
		but gets error:
		./pd_cli.py: line 15: import: command not found
		./pd_cli.py: line 16: import: command not found
		./pd_cli.py: line 17: import: command not found
		./pd_cli.py: line 18: import: command not found
		./pd_cli.py: line 19: import: command not found
		./pd_cli.py: line 20: import: command not found
		./pd_cli.py: line 21: import: command not found
		./pd_cli.py: line 24: import: command not found
		./pd_cli.py: line 27: syntax error near unexpected token `('
		./pd_cli.py: line 27: `class PdCli(cmd.Cmd):'
		
		
		Thanks,
		Swaroop


________________________________

		Date: Thu, 13 Aug 2015 06:59:53 -0700

		Subject: Re: [P4-dev] Doubts Regarding use of Register
		From: antonin at barefootnetworks.com
		To: swaroopthool1991 at outlook.com
		CC: p4-dev at p4.org
		
		
		Hi Swaroop,
		
		
		Please see inline
		

		On Wed, Aug 12, 2015 at 9:10 AM, Swaroop Thool <swaroopthool1991 at outlook.com> wrote:
		

			Hi Antonin,
			
			Thank you for your reply. 
			
			1) Furthermore, few basic operations implemented in many languages making it difficult to implement in P4.
			
			Is there way in P4 where I can keep record of values for particular flow/input.
			For example, I have stored 3 values of 1st input(like 1st IP address) in 3 different register arrays(one in each) through metadata field transfer. And again stored 3 values of 2nd input(like another IP address) in those 3 different register arrays but at different locations. Again for next 3rd input and so on. 
			Issue here is that ALL those values are in 3 register arrays and now I want to pick only that 3 values of 1st input. As metadata values are overwritten with latest values which cant rescue me. How to collect this 3 values of each input when register array almost becomes full or when inputs are stopped? If this is not the way, can I create run-time instances of metadatas for each new input which will hold values of that particular input/flow? But again here how can I refer to 1st flow metadatas after few flows?    
			


		I am sorry but it is very difficult for me to understand what you are trying to achieve here. I don't understand how you are filling your register arrays (like a queue?), what you are putting there, how you want to use it later...? If you can give some pseudo-code, I may be able to help you better.
		
		 


			2)Is there any print statement in P4? 
			


		That would not mean much, given that a) P4 is not a purely imperative language b) it is targeted at many kinds of target switches, including hardware ones.
		
		a) Where would you be able to print exactly? Only in actions, control flow, some parts of the parse states?
		
		b) Where would your message go?
		
		Also, user strings are not supported in P4, which kind of makes it difficult.
		
		In a nutshell, I don't think this belongs into standard P4. If you are writing P4 programs specifically for a software switch, you may be able to extend the P4 language with print statements that will be interpreted by your backend. But that would require modifying the frontend of the compiler (parser, hlir).
		
		
		We are working on a P4 debugger which will interact with the p4lang software switch. This debugger would let you step through a P4 program and print information about fields / metadata as you go. It will not be ready to be released for a while though.
		
		 


			3)Are there any comparison statement among values (e.g  max, min) ?
			


		I think it is in the works.
		
		
		
		Best,
		
		
		Antonin
		
		 



			Thanks,
			Swaroop
			
			
			
			
________________________________

			Date: Mon, 10 Aug 2015 08:31:32 -0700

			Subject: Re: [P4-dev] Doubts Regarding use of Register
			From: antonin at barefootnetworks.com
			To: swaroopthool1991 at outlook.com
			CC: p4-dev at p4.org
			
			
			Hi Swaroop,
			
			
			Sorry I sent you the wrong link, here is the correct one: https://github.com/p4lang/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61
			
			
			As for your questions:
			
			
			1) myfield is independent of the register, it should be a (any) header field / metadata field. Using the register name here will result in an error.
			
			
			2) Please submit an issue here: https://github.com/p4lang/p4c-behavioral/issues for the Python error you are seeing. You can just avoid using 'static' in your P4 program for now. I am pretty sure this attribute is ignored by the behavioral-model anyway.
			
			
			Thanks,
			
			
			Antonin
			

			On Mon, Aug 10, 2015 at 8:07 AM, Swaroop Thool <swaroopthool1991 at outlook.com> wrote:
			

				Hi Antonin,
				
				Thanks for the reply. 
				When I used the lines mentioned by you:
				
				
				register_read(myfield, r, runTimeValueofOtherMetadata); 
				
				add_to_field(myfield, 0x01);
				
				register_write(r, runTimeValueofOtherMetadata, myfield); 
				
				Which "myfield" actually here related to register r ? Can I use different field reference(e.g. some metadata field ref) instead of it?
				
				
				I was not getting compile error at start.It compiled for few lines however, later I got error stated as follows:
				
				/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/shell.py p4src/sample.p4 --gen-dir=/home/swaroop/p4-other/p4factory/targets/sample/build//bm/ --thrift --public-inc-path=/home/swaroop/p4-other/p4factory/targets/sample/build//inc/p4_sim --p4-prefix=sample
				WARNING: No error rule is defined for exclusive state 'pragma'
				WARNING: Token 'DIVIDE' defined, but not used
				WARNING: Token 'PPHASH' defined, but not used
				WARNING: Token 'MOD' defined, but not used
				WARNING: There are 3 unused tokens
				parsing successful
				Semantic warning: action 'no_op' is not reachable and will be removed
				semantic checking successful
				Header type standard_metadata_t not byte-aligned, adding padding
				validating:  True
				validating:  True
				validating:  True
				validating:  True
				Generating files in directory /home/swaroop/p4-other/p4factory/targets/sample/build/bm
				total phv length (in bytes): 124
				Traceback (most recent call last):
				  File "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/shell.py", line 130, in <module>
				    main()
				  File "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/shell.py", line 124, in main
				    dump_yaml = args.dump_yaml)
				  File "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/smart.py", line 1141, in render_dict_create
				    render_dict_populate_registers(render_dict, hlir)
				  File "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/smart.py", line 1076, in render_dict_populate_registers
				    r_info["binding"] = ("static", table)
				UnboundLocalError: local variable 'table' referenced before assignment
				make: *** [/home/swaroop/p4-other/p4factory/targets/sample/build//inc/p4_sim/rmt.h] Error 1
				
				
				P.S: Repository by the Link is not accessible 
				<https://github.com/barefootnetworks/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61> https://github.com/barefootnetworks/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61
				
				
				Thanks,
				Swaroop 
				
				
________________________________

				Date: Wed, 5 Aug 2015 14:29:07 -0700
				Subject: Re: [P4-dev] Doubts Regarding use of Register
				From: antonin at barefootnetworks.com
				To: swaroopthool1991 at outlook.com
				CC: p4-dev at p4.org


				Hi Swaroop,
				
				
				Thanks for your interest. I will give more details inline. However the basic answer to all your questions is that P4 registers are almost not supported at all (yet) in the behavioral model software switch. Some stateful operations are supported, but differe from what is in the spec.
				

				On Wed, Aug 5, 2015 at 12:08 PM, Swaroop Thool <swaroopthool1991 at outlook.com> wrote:
				

					Hi all ,
					
					Thanks for the answers. Few more questions:
					If I write-
					       register r {
					            width : 9;
					            static : table_which_invokes_register;
					            instance_count : 500;
					            attributes : saturating; }
					
					1) If I create register array of 500(cells) as above, is it like 1-D array whose location can be read/write? How to access that because I am getting syntax error when I used modify_field(). What is the proper syntax if I want to put some value at run-time generated location of array, say 50?
					


				You can do this, just not with modify_field(). You need to use register_read() and register_write(), which are described here: https://github.com/barefootnetworks/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61
				
				Something like this should work in an action:
				
				register_read(my_field, r, 50);
				
				add_to_field(my_field, 0xaba);
				
				register_write(r, 50, my_field);
				
				As you can see you can read / write a register, and once the value is in a field, you can do arithmetic on it. However you cannot operate directly on the register (for now).
				
				 

					
					2) Further extension to above,How can I store value 1 at location say, 50 in register array of 500 created above and later increment value 1 to 2 when same location is encountered and maintain those values?
					


				I guess the above answers your question?
				
				 

					
					3)What is layout declaration(instead of width declaration) means which require header_type_name?
					


				It is a convenient way of accessing register values using field names, no more. Let's say I have the following code:
				
				
				header_type my_header_type {
				
				  fields {
				
				    fA: 16;
				
				    fB: 32;
				
				    fC: 16;
				  }
				}
				
				
				register r2 {
				
				  layout: my_header_type;
				
				  instance_count: 100;
				
				}
				
				
				Then each cell in your register would be 64-bit wide. You would be able to write things like this: r2[50].fB
				
				So it is just a way to give "meaning" to the bits in a register cell.
				
				However this is NOT supported in the p4lang software switch.
				
				 

					
					4) If I create metadata for a packet to copy some value into its field, will value get updated with new one for another packet when same metadata is used for example : modify_field (metadata, somevalue) ?If yes, then how to maintain value of individual packets as I dont want to loose that values ? 
					


				registers will let you maintain state, the value of metadata will be overwritten with each new packet
				
				 

					
					5)OR should I use add_field() in above. What is the difference between both? 
					


				I don't see how this relates to 4)
				
				
				
				Also since you are using it in your code, I need to point out that attributes (e.g. saturating) are not supported in the switch yet.
				
				
				Best,
				
				
				Antonin
				
				 

					
					
					Thanks,
					Swaroop

					_______________________________________________
					P4-dev mailing list
					P4-dev at p4.org
					Listinfo - http://mail.p4.org/mailman/listinfo/p4-dev_p4.org
					Archives - http://mail.p4.org/pipermail/p4-dev_p4.org/
					




				-- 
				
				Antonin
				




			-- 
			
			Antonin
			




		-- 
		
		Antonin
		




	-- 
	
	Antonin
	




-- 

Antonin



More information about the P4-dev mailing list