@@ -672,10 +672,9 @@ private void handleErrorResponse(io.grpc.Status status) {
672672 }
673673
674674 /**
675- * Receives a pipeline config from a client. Discards all but the p4info file and cookie,
676- * and compares the received p4info to the already present hardcoded p4info. If the two
677- * match, the cookie is stored and a success response is sent. If they do not, the cookie is
678- * disarded and an error is reported.
675+ * Receives a pipeline config from a client. We don't support this feature
676+ * in UP4. UP4 has a pre-configured pipeline config, that is populated
677+ * at runtime with sizes coming from the data plane.
679678 *
680679 * @param request A request containing a p4info and cookie
681680 * @param responseObserver The thing that is fed a response to the config request.
@@ -684,19 +683,12 @@ private void handleErrorResponse(io.grpc.Status status) {
684683 public void setForwardingPipelineConfig (P4RuntimeOuterClass .SetForwardingPipelineConfigRequest request ,
685684 StreamObserver <P4RuntimeOuterClass .SetForwardingPipelineConfigResponse >
686685 responseObserver ) {
687- // Currently ignoring device_id, role_id, election_id, action
688- log .info ("Received setForwardingPipelineConfig message." );
689- P4InfoOuterClass .P4Info otherP4Info = request .getConfig ().getP4Info ();
690- if (!otherP4Info .equals (p4Info )) {
691- log .warn ("Someone attempted to write a p4info file that doesn't match our hardcoded one! What a jerk" );
692- } else {
693- log .info ("Received p4info correctly matches hardcoded p4info. Saving cookie." );
694- pipeconfCookie = request .getConfig ().getCookie ().getCookie ();
695- }
696-
697- // Response is currently defined to be empty per p4runtime.proto
698- responseObserver .onNext (P4RuntimeOuterClass .SetForwardingPipelineConfigResponse .getDefaultInstance ());
699- responseObserver .onCompleted ();
686+ log .info ("Attempted setForwardingPipelineConfig, not supported in UP4" );
687+ responseObserver .onError (
688+ io .grpc .Status .UNIMPLEMENTED
689+ .withDescription ("setForwardingPipelineConfig not supported in UP4" )
690+ .asException ()
691+ );
700692 }
701693
702694 /**
@@ -709,31 +701,45 @@ public void setForwardingPipelineConfig(P4RuntimeOuterClass.SetForwardingPipelin
709701 public void getForwardingPipelineConfig (P4RuntimeOuterClass .GetForwardingPipelineConfigRequest request ,
710702 StreamObserver <P4RuntimeOuterClass .GetForwardingPipelineConfigResponse >
711703 responseObserver ) {
712-
713- responseObserver .onNext (
714- P4RuntimeOuterClass .GetForwardingPipelineConfigResponse .newBuilder ()
715- .setConfig (
716- P4RuntimeOuterClass .ForwardingPipelineConfig .newBuilder ()
717- .setCookie (P4RuntimeOuterClass .ForwardingPipelineConfig .Cookie .newBuilder ()
718- .setCookie (pipeconfCookie ))
719- .setP4Info (setPhysicalSizes (p4Info ))
720- .build ())
721- .build ());
722- responseObserver .onCompleted ();
704+ try {
705+ errorIfSwitchNotReady ();
706+ responseObserver .onNext (
707+ P4RuntimeOuterClass .GetForwardingPipelineConfigResponse .newBuilder ().setConfig (
708+ P4RuntimeOuterClass .ForwardingPipelineConfig .newBuilder ()
709+ .setCookie (P4RuntimeOuterClass .ForwardingPipelineConfig .Cookie .newBuilder ()
710+ .setCookie (pipeconfCookie ))
711+ .setP4Info (setPhysicalSizes (p4Info ))
712+ .build ())
713+ .build ());
714+ responseObserver .onCompleted ();
715+ } catch (StatusException e ) {
716+ // FIXME: make it p4rt-compliant
717+ // From P4RT specs: "If a P4Runtime server is in a state where
718+ // the forwarding-pipeline config is not known, the top-level config
719+ // field will be unset in the response. Examples are (i) a server
720+ // that only allows configuration via SetForwardingPipelineConfig
721+ // but this RPC hasn't been invoked yet, (ii) a server that is
722+ // configured using a different mechanism but this configuration
723+ // hasn't yet occurred." - (ii) is the UP4 case -.
724+ // So, we shouldn't return an error, but simply set an empty config.
725+ // However, we do return an error in this way it's easier for
726+ // pfcp-agent to manage this case.
727+ responseObserver .onError (e );
728+ }
723729 }
724730
725731
726732 private void errorIfSwitchNotReady () throws StatusException {
727733 if (!up4Service .configIsLoaded ()) {
728734 log .warn ("UP4 client attempted to read or write to logical switch before an app config was loaded." );
729- throw io .grpc .Status .UNAVAILABLE
735+ throw io .grpc .Status .FAILED_PRECONDITION
730736 .withDescription ("App config not loaded." )
731737 .asException ();
732738 }
733739 if (!up4Service .isReady ()) {
734740 log .warn ("UP4 client attempted to read or write to logical switch " +
735741 "while the physical device was unavailable." );
736- throw io .grpc .Status .UNAVAILABLE
742+ throw io .grpc .Status .FAILED_PRECONDITION
737743 .withDescription ("Physical switch unavailable." )
738744 .asException ();
739745 }
0 commit comments