The argument Shylock uses in this speech is the one he uses throughout The Merchant of Venice and which eventually brings about his downfall. The pigs, cats, rats, and bagpipes are not really necessary to illustrate his point, which is simply this: as long as he stays within the letter of the law, he does not have to be either humane or reasonable. He made a contract, and the contract is legally binding. What would the court do, he asks, if there were a rat in his house, and he decided to pay the vast sum of ten thousand ducats to have it poisoned? This would clearly be an unreasonable decision, but the bad bargain he made with the exterminator would not be anyone else's business.
Shylock is confident in Venetian law because legal certainty, even more than justice, is the bedrock of civilization. The society in which he lives is not fair; he himself has frequently experienced its unfairness, but it is rigid and clear. His argument and his confidence are logical because of the technical rigidity with which the law must operate. It does not matter if he is a good person or a bad one, or if he is being sensible or absurd: the law protects him in the same way. Of course, this rigidity is shortly to become a problem for Shylock, but this is because of a technical oversight, which does not impact the logic of his reliance on legal certainty here.