diff --git a/src/flower_datapath.erl b/src/flower_datapath.erl index 8070e0e..35def68 100644 --- a/src/flower_datapath.erl +++ b/src/flower_datapath.erl @@ -39,7 +39,7 @@ handle_sync_event/4, handle_info/3, terminate/3, code_change/4]). -export([setup/2, setup/3, open/2, open/3, connecting/2, connecting/3, connected/2, connected/3]). -export([install_flow/10, send_packet/4, send_buffer/4, send_packet/5, portinfo/2, - remove_flow/10, remove_all_flows/1, modify_flow/11]). + remove_flow/10, remove_all_flows/1, modify_flow/10, modify_flow/11]). -export([counters/0, counters/1, features/1, features_all/0]). -define(SERVER, ?MODULE). @@ -156,6 +156,11 @@ remove_flow(Sw, Match, Cookie, IdleTimeout, HardTimeout, modify_flow(Sw, Match, Cookie, delete, IdleTimeout, HardTimeout, Actions, BufferId, Priority, InPort, Packet). +modify_flow(Sw, Match, Cookie, IdleTimeout, HardTimeout, + Actions, BufferId, Priority, InPort, Packet) -> + modify_flow(Sw, Match, Cookie, modify, IdleTimeout, HardTimeout, + Actions, BufferId, Priority, InPort, Packet). + modify_flow(Sw, Match, Cookie, ModCmd, IdleTimeout, HardTimeout, Actions, BufferId, Priority, InPort, Packet) -> MatchBin = flower_packet:encode_match(Match), @@ -275,7 +280,7 @@ setup({accept, Socket}, State) -> ?DEBUG("got setup~n"), NewState = State#state{role = server, socket = Socket}, ?DEBUG("NewState: ~p~n", [NewState]), - ok = inet:setopts(Socket, [{active, once}]), + ok = setopts(Socket, [{active, once}]), send_request(hello, <<>>, {next_state, open, NewState, ?CONNECT_TIMEOUT}); setup(timeout, State = #state{role = client, arguments = Arguments}) -> @@ -288,7 +293,7 @@ setup({connect, Arguments}, State = #state{transport = TransportMod}) -> {ok, Socket} -> NewState1 = NewState0#state{socket = Socket}, ?DEBUG("NewState: ~p~n", [NewState1]), - ok = inet:setopts(Socket, [{active, once}]), + ok = setopts(Socket, [{active, once}]), send_request(hello, <<>>, {next_state, open, NewState1, ?CONNECT_TIMEOUT}); _ -> {next_state, setup, NewState0, ?RECONNECT_TIMEOUT} @@ -439,7 +444,7 @@ connected({stats_request, Type, Msg, Timeout}, From, State) -> %% @end %%-------------------------------------------------------------------- handle_event(activate_socket, StateName, State = #state{socket = Socket}) -> - ok = inet:setopts(Socket, [{active, once}]), + ok = setopts(Socket, [{active, once}]), {next_state, StateName, State}; handle_event(_Event, StateName, State) -> @@ -481,7 +486,8 @@ handle_sync_event(_Event, _From, StateName, State) -> %% {stop, Reason, NewState} %% @end %%-------------------------------------------------------------------- -handle_info({tcp, Socket, Data}, StateName, #state{socket = Socket} = State) -> +handle_info({Proto, Socket, Data}, StateName, #state{socket = Socket} = State) + when Proto == tcp orelse Proto == ssl -> ?DEBUG(flower_tools:hexdump(Data)), {Msg, DataRest} = decode_of_pkt(<<(State#state.pending)/binary, Data/binary>>, State), State0 = inc_counter(State, recv, raw_packets), @@ -489,8 +495,8 @@ handle_info({tcp, Socket, Data}, StateName, #state{socket = Socket} = State) -> ?DEBUG("handle_info: decoded: ~p~nrest: ~p~n", [Msg, DataRest]), case Msg of - [] -> - ok = inet:setopts(Socket, [{active, once}]), + [] -> + ok = setopts(Socket, [{active, once}]), {next_state, StateName, State1}; [First|Next] -> @@ -502,7 +508,7 @@ handle_info({tcp, Socket, Data}, StateName, #state{socket = Socket} = State) -> next_state -> case Next of [] -> - ok = inet:setopts(Socket, [{active, once}]), + ok = setopts(Socket, [{active, once}]), Reply; _ -> @@ -520,6 +526,9 @@ handle_info({tcp, Socket, Data}, StateName, #state{socket = Socket} = State) -> end; handle_info({tcp_closed, Socket}, _StateName, State) -> + handle_socket_error(Socket, State); + +handle_info({ssl_closed, Socket}, _StateName, State) -> handle_socket_error(Socket, State). %%-------------------------------------------------------------------- @@ -705,3 +714,12 @@ decode_of_pkt(Data, _State) -> %% best effort try even when the version it to high, %% really for hello only.... flower_packet_v12:decode(Data). + +setopts(Socket, Opts) -> + try + {ok,_} = ssl:sockname(Socket), % check if ssl socket + ssl:setopts(Socket, Opts) + catch + _:_ -> + inet:setopts(Socket, Opts) + end. diff --git a/src/flower_match.erl b/src/flower_match.erl index ef365ec..34097d1 100644 --- a/src/flower_match.erl +++ b/src/flower_match.erl @@ -20,7 +20,8 @@ -module(flower_match). --export([encode_ofp_matchflow/2, encode_ofp_match/1, decode_ofp_match/1]). +-export([encode_ofp_matchflow/2, encode_ofp_match/1, decode_ofp_match/1, + ofp_match/2]). %% -------------------------------------------------------------------- %% Include files @@ -111,9 +112,9 @@ ofp_match({tp_dst, TpDst}, #ofp_match{wildcards = Wildcards} = Match) -> ofp_match({nw_tos, NwTos}, #ofp_match{wildcards = Wildcards} = Match) -> Match#ofp_match{wildcards = Wildcards band (bnot ?OFPFW_NW_TOS), nw_tos = NwTos}; ofp_match({nw_src_mask, NwSrc, Mask}, #ofp_match{wildcards = Wildcards} = Match) -> - Match#ofp_match{wildcards = (Wildcards band bnot ?OFPFW_NW_SRC_MASK) bor (((32 - Mask) band 16#3F) bsl 8), nw_src = NwSrc}; + Match#ofp_match{wildcards = (Wildcards band bnot ?OFPFW_NW_SRC_MASK) bor ((Mask band 16#3F) bsl 8), nw_src = NwSrc}; ofp_match({nw_dst_mask, NwDst, Mask}, #ofp_match{wildcards = Wildcards} = Match) -> - Match#ofp_match{wildcards = (Wildcards band bnot ?OFPFW_NW_DST_MASK) bor (((32 - Mask) band 16#3F) bsl 14), nw_dst = NwDst}. + Match#ofp_match{wildcards = (Wildcards band bnot ?OFPFW_NW_DST_MASK) bor ((Mask band 16#3F) bsl 14), nw_dst = NwDst}. -spec encode_ofp_match(list(term())) -> ofp_match(). encode_ofp_match(MatchSpec) ->