A funny thing happened to Peter Frampton when he went shopping in Ipanema the other day.

Somebody asked him if he was Rod Stewart.

For the group of surfers who had stumbled across Frampton on their way home from the beach, it was an understandable case of mistaken identity. Rod Stewart actually was in town, and to confuse things even further for Brazilians, who have a hard time telling funk from punk, so were Elton John and various members of the Sex Pistols. Besides, the guy coming down the street obviously had to be a celebrity of some kind. After all, most tourists who come here at carnival time don't go looking for a pair of swim trunks with a full squadron of bodyguards, managers, secretaries, press agents and photographers in tow.

Vacationing rock stars, however, are an altogether different breed, as Rio residents are discovering. For the first time ever, Rio's famous festival, which ends today, has attracted some of rock's biggest names, and the Cariocas, more accustomed to the ways of visiting French and Italian movie stars, don't quite know what to make of it.

Not that the rock 'n' rollers on holiday are behaving any different from the way they normally do at home. They're spending just as much money, going to just as many parties, causing just as much trouble, and working just as hard to get publicity while pretending just as unconvincingly that they don't want it.

Leading the way has been Rod Stewart. When the carrot-haired singer arrived here in mid-January on a Concorde flight from Paris, saying he was tired and had come to Brazil just to rest, he was unknown even to many in the greeting committee of 300 teenagers his record company had lured to the airport with offers of free records and an air-conditioned bus ride.

But when Stewart checked into the presidential suite at the ritzy Copacabana Palace Hotel and set about having himself a good time, all that began to change. It took just one party to put him on the map here and make him a daily item for Rio's gossip columnists.

By local standards, it was no ordinary party that Stewart threw in his quarters. True, no one was particularly surprised when at 2 a.m. the hotel management asked Stewart and the 200 "friends" he had rounded up for an intimate little get-together to please quiet things down.

But when it was reported that the hotel management later handed Stewart a bill for nearly $5,000 to cover the costs of broken furniture, that made Stewart an object of curiosity. Busting up furniture was something that carnival regulars such as Alain Delon and Ursula Andress simply had never done.

At a press conference a few days later, though, Stewart shrugged off his expensive caper, telling Brazilian reporters that he had sold two million records in the last four weeks and had grossed $3 million on his last tour. As for the Beatles: "I've never heard of them."

The weekend before carnival the cocky Stewart was back at it again. The Formula One automobile race and a big soccer game had been scheduled for the same afternoon, and Stewart, a former professional soccer player, was intent on seeing both events, even though they were on opposite ends of the city.

Money being no object, Stewart found a way to beat the traffic and the clock: he chartered a helicopter. The race completed, he hopped into the aircraft and zoomed over to the 200,000-seat Maracana Stadium in time to catch all the big Flamengo-Vasco Da Gama game.

With Stewart's image firmly fixed in the public mind, late arrivals Frampton and Elton John have been doing their best to catch up in the carnival publicity sweepstakes. Though both performers arrived here mouthing the Greta Garbo line about wanting to be left alone, copies of their "secret itenerary" were soon distributed to the press.

Since then, Frampton and John have been following a very carefully scheduled program that has them spending their days on yachts and at beaches and spending their nights dining with Rio high society and dancing at fashionable night spot like Regine's. Naturally, there are lots of photo opportunities for the press at every stop.

Brazilian reporters have found, however, that getting either Frampton or John to talk is another matter altogether. When Frampton canceled a press conference at the last minute, saying that he was "sick" and needed to rest, the press rushed over to John's hotel, arriving just in time to see Frampton sneaking in the door to visit his crony.

The three stars made their first joint appearance at Friday night's superchic "Sugar Loaf Carnival Costume Ball," with Stewart showing up in a flamenco uniform and Frampton opting for civilian clothes. Elton John, dressed as a sailor, "would have gone unnoticed altogether," sniffed one chronicler of the event, had it not been for his two burly bodyguards --who were also costumed as sailors.

The Sex Pistols, on the other hand, have been keeping a low profile. When it was first announced that guitarist Steve Jones and drummer Paul Cook were coming for carnival, people began joking that, in view of their punk reputation, the Sex Pistols would shut the elegant beaches of Ipanema and Copacabana in favor of Ramos -- a polluted piece of strand where bathers are frequently assaulted.

But then it was discovered that the Pistols could get no hotel accommodations at all, and a disc jockey began an "Adopt a Punk' campaign. "Despite their criticism of the pet set lifestyle, the two Pistols ended up at a mansion owned by an executive of their record company, and have been spending most of their time lounging poolside.

To the surprise of their Brazilian hosts, the two punk rockers expressed no interest in seeing carnival or meeting Stewart, Frampton or John. Instead, they asked to be introduced to Ronald Biggs, the mastermind of England's "Great Train Robbery" of the early '60s, who now lives here, beyond the reach of extradition laws.

That was easy enough to arrange, but some of the other requests made by visiting rock 'n' rollers have made life very difficult for the Brazilians charged with keeping the pop celebrities happy. Finding bodyguards and cooks was no problem, but coming by the limousine that both Frampton and John demanded was no easy matter.

Black Cadillacs are not the most plentiful commodity in Brazil, and after much searching, the record company could only find one. That created a problem that required the wisdom of Solomon if it were to be resolved with out wounding egos. Who gets the limo, Elton John or Peter Frampton?

After much soul-searching, a compromise acceptable to all was finally reached: both stars would use the black Cadillac.

Or rather, they would take turns using it. When it was the other fellow's turn, the odd man out would simply have to humble himself and accept being driven around in a plain old Ford Galaxie.