use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.
the class HwvtepTerminationPointListener method getVlanBindings.
private List<VlanBindings> getVlanBindings(List<L2gatewayConnection> l2GwConns, NodeId hwvtepNodeId, String psName, String newPortId) {
List<VlanBindings> vlanBindings = new ArrayList<>();
for (L2gatewayConnection l2GwConn : l2GwConns) {
L2gateway l2Gateway = L2GatewayConnectionUtils.getNeutronL2gateway(broker, l2GwConn.getL2gatewayId());
if (l2Gateway == null) {
LOG.error("L2Gateway with id {} is not present", l2GwConn.getL2gatewayId().getValue());
} else {
String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(l2GwConn.getNetworkId().getValue());
List<Devices> l2Devices = l2Gateway.getDevices();
for (Devices l2Device : l2Devices) {
String l2DeviceName = l2Device.getDeviceName();
if (l2DeviceName != null && l2DeviceName.equals(psName)) {
for (Interfaces deviceInterface : l2Device.getInterfaces()) {
if (deviceInterface.getInterfaceName().equals(newPortId)) {
if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {
vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(hwvtepNodeId, vlanId, logicalSwitchName));
}
} else {
// Use defaultVlanId (specified in L2GatewayConnection) if Vlan
// ID not specified at interface level.
Integer segmentationId = l2GwConn.getSegmentId();
int defaultVlanId = segmentationId != null ? segmentationId : 0;
vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(hwvtepNodeId, defaultVlanId, logicalSwitchName));
}
}
}
}
}
}
}
return vlanBindings;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.
the class NaptEventHandler method prepareAndSendPacketOut.
private void prepareAndSendPacketOut(NAPTEntryEvent naptEntryEvent, Long routerId) {
// Send Packetout - tcp or udp packets which got punted to controller.
BigInteger metadata = naptEntryEvent.getPacketReceived().getMatch().getMetadata().getMetadata();
byte[] inPayload = naptEntryEvent.getPacketReceived().getPayload();
Ethernet ethPkt = new Ethernet();
if (inPayload != null) {
try {
ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.error("prepareAndSendPacketOut : Failed to decode Packet", e);
return;
}
}
long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
LOG.debug("prepareAndSendPacketOut : portTag from incoming packet is {}", portTag);
String interfaceName = getInterfaceNameFromTag(portTag);
LOG.debug("prepareAndSendPacketOut : interfaceName fetched from portTag is {}", interfaceName);
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = null;
int vlanId = 0;
iface = interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
if (iface == null) {
LOG.error("prepareAndSendPacketOut : Unable to read interface {} from config DataStore", interfaceName);
return;
}
List<ActionInfo> actionInfos = new ArrayList<>();
IfL2vlan ifL2vlan = iface.getAugmentation(IfL2vlan.class);
if (ifL2vlan != null && ifL2vlan.getVlanId() != null) {
vlanId = ifL2vlan.getVlanId().getValue() == null ? 0 : ifL2vlan.getVlanId().getValue();
}
InterfaceInfo infInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
if (infInfo == null) {
LOG.error("prepareAndSendPacketOut : error in getting interfaceInfo from Operation DS");
return;
}
byte[] pktOut = buildNaptPacketOut(ethPkt);
if (ethPkt.getEtherType() != (short) NwConstants.ETHTYPE_802_1Q) {
// VLAN Access port
LOG.debug("prepareAndSendPacketOut : vlanId is {}", vlanId);
if (vlanId != 0) {
// Push vlan
actionInfos.add(new ActionPushVlan(0));
actionInfos.add(new ActionSetFieldVlanVid(1, vlanId));
} else {
LOG.debug("prepareAndSendPacketOut : No vlanId {}, may be untagged", vlanId);
}
} else {
// VLAN Trunk Port
LOG.debug("prepareAndSendPacketOut : This is VLAN Trunk port case - need not do VLAN tagging again");
}
if (pktOut != null) {
String routerName = NatUtil.getRouterName(dataBroker, routerId);
long tunId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
sendNaptPacketOut(pktOut, infInfo, actionInfos, tunId);
} else {
LOG.warn("prepareAndSendPacketOut : Unable to send Packet Out");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.
the class ElanL2GatewayUtils method deleteVlanBindingsFromL2GatewayDevice.
/**
* Delete vlan bindings from l2 gateway device.
*
* @param nodeId
* the node id
* @param hwVtepDevice
* the hw vtep device
* @param defaultVlanId
* the default vlan id
* @return the listenable future
*/
public ListenableFuture<Void> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice, Integer defaultVlanId) {
if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) {
String errMsg = "HwVtepDevice is null or interfaces are empty.";
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName());
return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
String phyPortName = deviceInterface.getInterfaceName();
if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {
HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, phyPortName, vlanId);
}
} else {
// Use defaultVlanId (specified in L2GatewayConnection) if Vlan
// ID not specified at interface level.
HwvtepUtils.deleteVlanBinding(tx, physicalSwitchNodeId, phyPortName, defaultVlanId);
}
}
LOG.info("Deleted Hwvtep VlanBindings from config DS. NodeID: {}, hwVtepDevice: {}, defaultVlanId: {} ", nodeId.getValue(), hwVtepDevice, defaultVlanId);
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.
the class ElanItmUtils method getExternalTunnelItmEgressAction.
/**
* Builds the list of actions to be taken when sending the packet over an
* external VxLan tunnel interface, such as stamping the VNI on the VxLAN
* header, setting the vlanId if it proceeds and output the packet over the
* right port.
*
* @param srcDpnId
* Dpn where the tunnelInterface is located
* @param torNode
* NodeId of the ExternalDevice where the packet must be sent to.
* @param vni
* Vni to be stamped on the VxLAN Header.
* @return the external itm egress action
*/
public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, NodeId torNode, long vni) {
List<Action> result = Collections.emptyList();
GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder().setDestinationNode(torNode.getValue()).setSourceNode(srcDpnId.toString()).setTunnelType(TunnelTypeVxlan.class).build();
Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> output = itmRpcService.getExternalTunnelInterfaceName(input);
try {
if (output.get().isSuccessful()) {
GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId in project netvirt by opendaylight.
the class ElanItmUtils method getInternalTunnelItmEgressAction.
/**
* Builds the list of actions to be taken when sending the packet over an internal VxLAN tunnel interface, such
* as setting the serviceTag/segmentationID on the VNI field of the VxLAN header, setting the vlanId if it proceeds
* and output the packet over the right port.
*
* @param sourceDpnId
* Dpn where the tunnelInterface is located
* @param destinationDpnId
* Dpn where the packet must be sent to. It is used here in order
* to select the right tunnel interface.
* @param tunnelKey
* Tunnel key to be sent on the VxLAN header.
* @return the internal itm egress action
*/
public List<Action> getInternalTunnelItmEgressAction(BigInteger sourceDpnId, BigInteger destinationDpnId, long tunnelKey) {
List<Action> result = Collections.emptyList();
LOG.trace("In getInternalItmEgressAction Action source {}, destination {}, serviceTag/Vni {}", sourceDpnId, destinationDpnId, tunnelKey);
Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
GetTunnelInterfaceNameInput input = new GetTunnelInterfaceNameInputBuilder().setDestinationDpid(destinationDpnId).setSourceDpid(sourceDpnId).setTunnelType(tunType).build();
Future<RpcResult<GetTunnelInterfaceNameOutput>> output = itmRpcService.getTunnelInterfaceName(input);
try {
if (output.get().isSuccessful()) {
GetTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
LOG.info("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
result = buildTunnelItmEgressActions(tunnelIfaceName, tunnelKey);
} else {
LOG.trace("Tunnel interface doesn't exist between srcDpId {} dstDpId {}", sourceDpnId, destinationDpnId);
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
}
return result;
}
Aggregations