TepCommandHelper { @SuppressWarnings("checkstyle:IllegalCatch") public void createLocalCache(Uint64 dpnId, String ipAddress, String transportZone) throws TepException { CHECK.incrementAndGet(); IpAddress ipAddressObj; final VtepsKey vtepkey = new VtepsKey(dpnId); ipAddressObj = IpAddressBuilder.getDefaultInstance(ipAddress); if (checkTepPerTzPerDpn(transportZone, dpnId)) { handleError("Only one end point per transport Zone per Dpn is allowed"); return; } Vteps vtepCli = new VtepsBuilder().setDpnId(dpnId).setIpAddress(ipAddressObj).withKey(vtepkey) .build(); if (transportZonesHashMap.containsKey(transportZone)) { List<Vteps> vtepListTemp = transportZonesHashMap.get(transportZone); if (!vtepListTemp.contains(vtepCli)) { vtepListTemp.add(vtepCli); } } else { List<Vteps> vtepListTemp = new ArrayList<>(); vtepListTemp.add(vtepCli); transportZonesHashMap.put(transportZone, vtepListTemp); } } @Inject  TepCommandHelper(final DataBroker dataBroker, final ItmConfig itmConfig,
                            final UnprocessedTunnelsStateCache unprocessedTunnelsStateCache); @PostConstruct void start(); @PreDestroy void close(); @SuppressWarnings("checkstyle:IllegalCatch") void createLocalCache(Uint64 dpnId, String ipAddress,
                                 String transportZone); TransportZone getTransportZone(String transportZoneName); TransportZones getAllTransportZones(); boolean checkTepPerTzPerDpn(String tzone, Uint64 dpnId); @SuppressWarnings("checkstyle:IllegalCatch") void buildTeps(); List<String> showTeps(boolean monitorEnabled, int monitorInterval); @SuppressWarnings("checkstyle:RegexpSinglelineJava") void showCache(String cacheName); @SuppressWarnings("checkstyle:IllegalCatch") void deleteVtep(Uint64 dpnId, String ipAddress,
                           String transportZone); @SuppressWarnings("checkstyle:IllegalCatch") void deleteOnCommit(); @SuppressWarnings("checkstyle:RegexpSinglelineJava") void showState(Collection<StateTunnelList> tunnelLists, boolean tunnelMonitorEnabled); void showBridges(Map<Uint64, OvsdbBridgeRef> dpnIdBridgeRefMap); boolean isInCache(Uint64 dpnId, String ipAddress,
                             String transportZone); void configureTunnelType(String transportZoneName, String tunnelType); void configureTunnelMonitorParams(boolean monitorEnabled, String monitorProtocol); void configureTunnelMonitorInterval(int interval); void handleError(String errorMessage); @SuppressWarnings("checkstyle:RegexpSinglelineJava") void showOfPorts(Collection<OfTep> ofTeps);  }
@Test public void testCreateLocalCacheTzonesEmpty() { try { tepCommandHelper.createLocalCache(dpId1,tepIp1,transportZone1); } catch (TepException e) { LOG.error(e.getMessage()); } verify(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,transportZoneIdentifier); }
@Test public void testCreateLocalCacheWithoutcheckExistingSubnet() { transportZoneNew = new TransportZoneBuilder().setZoneName(transportZone1).setTunnelType(tunnelType2) .setDeviceVteps(deviceVtepsList).setVteps(vtepsList).build(); doReturn(FluentFutures.immediateFluentFuture(Optional.of(transportZoneNew))).when(mockReadTx).read( LogicalDatastoreType.CONFIGURATION,transportZoneIdentifier); lenient().doReturn(FluentFutures.immediateFluentFuture(Optional.empty())) .when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,transportZonesIdentifier); try { tepCommandHelper.createLocalCache(dpId1,tepIp1,transportZone1); tepCommandHelper.createLocalCache(dpId2,tepIp1,transportZone1); } catch (TepException e) { LOG.error(e.getMessage()); } verify(mockReadTx, times(2)).read(LogicalDatastoreType.CONFIGURATION,transportZoneIdentifier); }
@Test public void testCreateLocalCacheWithcheckExistingSubnet() { transportZoneNew = new TransportZoneBuilder().setZoneName(transportZone1).setTunnelType(tunnelType2) .setDeviceVteps(deviceVtepsList).setVteps(vtepsList).build(); Optional<TransportZone> optionalTransportZone = Optional.of(transportZoneNew); doReturn(FluentFutures.immediateFluentFuture(optionalTransportZone)).when(mockReadTx).read(LogicalDatastoreType .CONFIGURATION,transportZoneIdentifier); lenient().doReturn(FluentFutures.immediateFluentFuture(Optional.empty())) .when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,transportZonesIdentifier); try { tepCommandHelper.createLocalCache(dpId1,tepIp1,transportZone1); tepCommandHelper.createLocalCache(dpId2,tepIp1,transportZone1); } catch (TepException e) { LOG.error(e.getMessage()); } verify(mockReadTx, times(2)).read(LogicalDatastoreType.CONFIGURATION,transportZoneIdentifier); }
@SuppressWarnings("checkstyle:IllegalCatch") @Test public void testCreateLocalCacheGtwyIpNull() { try { tepCommandHelper.createLocalCache(dpId1,tepIp1,transportZone1); } catch (TepException e) { LOG.error(e.getMessage()); } LOG.debug("gateway is null"); }