Rank-based policies represent a promising approach for designing message forwarding algorithms that meet the needs of opportunistic networks. In fact, they combine low computation and communication costs with good performance in terms of both latency and delivery rates. Nonetheless, they highly depend on the mobility scenario relevant to the user, and a forwarding policy with good performances in heterogeneous settings has yet to be designed. In this paper, we propose to provide each mobile device with novel autonomic observation and reasoning components according to the following objectives: enable the device (i) to achieve awareness about the behavior of the mobility scenario it is moving in, and (ii) to identify the role played by the device within the set of other moving devices. These components are combined into a self-configuring forwarding algorithm that uses them to locally install both the utility function and the relevant settings suitable for the sensed configuration. Through of extensive simulations, this paper shows that by properly discriminating between roles it is possible to derive a self-configuring forwarding mechanism that constantly performs well in different mobility settings.