Defense Secretary Jim Mattis and Department of Homeland Security Secretary Kirstjen Nielsen visited the southern Texan border on Wednesday to bolster troops deployed to support border agents trying to prevent caravans of migrants from illegally crossing.

“We’ve come down here to pay our respects,” Mattis told soldiers deployed at McAllen, Texas. “We know what you’re doing, we track it every day … Sometimes you got to come down and see the troops,” he said.

Mattis, a retired Marine general, told a group of young enlisted soldiers, “The eyes of the world right now, and certainly the Americans, are on you.”

“We want legal immigration — that’s part of what makes America good,” he said. “But illegal — we’re going to carry out the law.”

As of Wednesday, there were about 5,900 active duty troops deployed to the border to support the DHS and Customs and Border Protection (CBP).

Mattis ordered the deployment last month when a request came from DHS to help CBP agents reinforce the border against several thousands of migrants traveling in caravans from Central America trekking north to the U.S. border.

Along the way, one caravan overran the border from Guatemala into Mexico, alarming U.S. authorities. Some migrants threw rocks and injured Mexican police.

Mattis said he is not sure when the deployments will end as the situation is dynamic. He said, right now, troops are placing obstacles along the border in Texas, Arizona, and California where they are deployed. They have also been transporting and supporting CBP personnel, helping with logistics, and any needed medical support.

While he was speaking to a group of enlisted soldiers in a tent, at least one stood and expressed his deep gratitude over Mattis coming to visit.

“I’m going to be that guy, but is there any chance our group can get a photo with you and secretary?” he asked. Mattis joked, “Oh for crying out loud,” before suggesting they head outside to take the photo.

On the plane on the way to Texas, Mattis told reporters traveling with him that he believed the mission was “absolutely legal,” “moral and ethical.”

“Border security is part of national security. Our units are in a position to enable the Border Patrol’s law enforcement operations. We determined that that mission was absolutely legal and this is also reviewed by Department of Justice lawyers,” he told them. “It’s obviously a moral and ethical mission to support our border patrolmen.”

Defense Secretary James Mattis defends the deployment of thousands of active duty troops to the border with Mexico Wednesday, calling it "a moral and ethical mission to support our border patrolmen." https://t.co/P3l3YxfD0M pic.twitter.com/nTKh51L2AO — ABC News (@ABC) November 15, 2018

He said he did not anticipate any troops coming into direct contact with migrants or taking any kind of law enforcement role. The only troops who will be armed will be those protecting other troops, he said.

Mattis said the deployment gave troops the ability to train and rehearse helicopter deployment. He said he talked to one officer who told him that it was “very good training” because they are rehearsing everything they would do in a deployment elsewhere in the world.

Mattis bristled when asked what he thought about retired Chairman of the Joint Chiefs of Staff Gen. Martin Dempsey and Democrats who criticized the troop deployment as a “wasteful deployment.”

“Well, I would refer them to the New York Times and what happened to the Mexican police, and I would just leave that to the secretary of the Department of Homeland Security. She’s a professional. … The people responsible for the mission are the ones I listen to on something like this,” he said.

He also defended the necessity of the mission.

“I think that it’s very clear that support to border patrol is necessary right now. If they come to me and say, ‘We do not have the people to put in barbed wire. We don’t have the capability to use helicopters and move people around. We don’t have the helicopters’ … I’d defer to their judgment. They’re the ones who are held responsible to maintain our sovereignty.”

Asked whether troops may be still deployed over Thanksgiving and Christmas, Mattis said there are U.S. troops deployed all over the world over the holidays.

“We’re a 365-day-a-year military. Rain or shine, light or dark, cold weather or hot weather — we have an all-weather force that’s on duty 24/7,” he said. “All I can say to the American people: Welcome to your military. It’s on duty.”